Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

504
Views
Idiomatic way in Python to indicate an unused module import is intentional

Sometimes a Python module import that appears to be unused, is in fact essential to the proper functioning of the program. Having seemingly unused imports gives rise to spurious messages from tools like PyFlakes, and can attract unwarranted attention from overzealous programmers. C++, for instance, has (since C++ 11) an idiomatic way to indicate this with the [[unused]] attribute (and [[maybe_unused]] since C++ 17).

I'm asking this question in particular in the context of web frameworks like Flask, where this is often the case. For example, this boilerplate code from a Flask application, which is essential for proper its function:

from app import auth_routes, app, db
from app.resources import api

I usually handle this situation by

import X
assert X is not None # Explanatory comment

Is there a way that's more explicit about intent and more "Pythonic" to accomplish this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Every tool will have its own way of error-suppression. For instance:

Pylint:

import X  # pylint: disable=unused-import

Pyflakes:

import X  # NOQA

PyCharm:

# noinspection PyUnresolvedReferences
import X
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!