What does "# noqa" mean in Python comments?

When searching in a Python project, I found some lines with # noqa comments.

 import sys sys.path.append(r'C:\dev') import some_module # noqa 

What does noqa mean in Python? Is this specific to Python only?

+75
python comments terminology code-analysis pep8
source share
3 answers

Adding # noqa to a line means that the linter (a program that automatically checks the quality of the code) should not check this line. Any warnings that the code could generate will be ignored.

This line may have something that "looks bad" for the linter, but the developer understands and intends to do this for some reason.

For more information, see the Flake8 Documentation for Selecting and Ignoring Violations .

+104
source share

noqa = NO-QA (NO Quality Assurance)

Typically, in Python programming, PEP8 warnings are ignored.

Simply put, C # noqa strings at the end will be ignored by linter programs and will not generate any warnings.

+27
source share

You know? Even Guido van Rossum (creator of Python) has asked this question before : D

A bit of etymology # noqa :

It used to be "nopep8", but when Flake8 and Pep8 wanted a common qualifier, @florentx suggested "NoQA" as in "No Quality Assurance" (iirc), and it got stuck.

Some basic uses of # noqa (with flake8 ):

  • # flake8: noqa : files containing this line are skipped
  • lines that contain a comment # noqa at the end: will not # noqa warnings
  • # noqa: <error> , for example, # noqa: E234 at the end: ignore certain errors in the string
    • You can specify multiple error codes separated by commas
    • a colon before the code list is required
0
source share

All Articles