What does # noqa mean in Python comments (e.g. # noqa: E402)?
Codemia Knowledge Hub ·
# noqa at the end of a Python line tells the linter to skip checking that line. The name stands for "no quality assurance." It originated with Flake8 and is honored by Flake8 (including the pycodestyle and pyflakes checks it runs), pycodestyle, and Ruff. Standalone pyflakes ignores it. Adding a code, as in # noqa: E402, suppresses only that rule.
Treat it as an exception mechanism: fix the code when possible, suppress narrowly when necessary, and document why. Teams that overuse # noqa hide real defects behind blanket suppressions.
How # noqa works
As a linter scans each line for violations, it checks whether the line ends with # noqa before reporting. If it does, the violation is dropped from the output.
The bare form suppresses every rule on the line:
That also hides violations you might want to see, like an unused import sitting next to a naming convention warning.
Suppressing specific rules with error codes
List the rule codes after a colon to suppress only those:
Separate multiple codes with commas:
F401 is "imported but unused" and E501 is "line too long." Everything else on the line is still checked.
Common Flake8 and Ruff codes, including E402
| Code | Rule | When to suppress |
F401 | Imported but unused | Re-exports in __init__.py |
F403 | Wildcard import used | Legacy modules requiring * imports |
E501 | Line too long | URLs or long string literals that cannot be broken |
E402 | Module-level import not at top | Imports that must follow sys.path manipulation |
W503 | Line break before binary operator | Style preference conflicts between tools |
E711 | Comparison to None | SQLAlchemy filter expressions using == None |
When # noqa is justified
Re-exports in __init__.py: When a package assembles its public API by importing names from submodules, the linter sees those imports as unused:
Compatibility imports: Libraries supporting multiple Python versions sometimes need conditional imports:
SQLAlchemy filter expressions: ORM filters compare to None with == on purpose, which triggers E711:
Generated code: Auto-generated files often break style rules by design, so a file-level suppression may be appropriate.
Suppressing a whole file
Flake8 supports a file-level directive, placed near the top of the file:
Ruff has a similar mechanism. Use it for auto-generated files or vendored third-party code, never for files your team maintains: it hides every present and future violation, so defects pile up silently.
Suppression syntax in other tools
If your project runs several tools, each respects only its own comments.
| Tool | Inline suppression syntax | File-level syntax |
| Flake8 | # noqa: F401 | # flake8: noqa |
| Ruff | # noqa: F401 (same as Flake8) | # ruff: noqa |
| Pylint | # pylint: disable=unused-import | # pylint: disable-all |
| Mypy | # type: ignore[assignment] | Per-file config in mypy.ini |
| Pyright | # pyright: ignore[reportGeneralTypeIssues] | Per-file config |
# noqa does nothing for Pylint, and # pylint: disable does nothing for Flake8.
Finding stale # noqa comments with Ruff
Ruff has become the dominant Python linter because of its speed. Besides honoring # noqa, ruff check --extend-select RUF100 flags # noqa comments that suppress rules no longer being violated, so you can clean up suppressions left behind by refactors.
Team rules for suppressions
Require specific codes: Ban bare # noqa in new code. In Ruff, enable RUF100. In Flake8, use the flake8-noqa plugin.
Require a rationale comment:
Track suppression counts: Audit # noqa occurrences periodically. A rising count without justifications suggests the team is avoiding fixes.
Related reading
- What does a bare asterisk do in a parameter list? What are keyword-only parameters?
- What does a leading . dot, period in an import statement in Python mean?
- What does asterisk mean in Python?
- What does axis in pandas mean?
- What does colon equal in Python mean?
- What does .contiguous do in PyTorch?
- What does double star/asterisk and star/asterisk do for parameters?
- What does enumerate mean?
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.