Categories
code-analysis comments pep8 python terminology

What does ‘# noqa’ mean in Python comments?

327

While searching through a Python project, I found a few lines commented with # noqa.

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

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

3

358

Adding # noqa to a line indicates that the linter (a program that automatically checks code quality) should not check this line. Any warnings that code may have generated will be ignored.

That line may have something that “looks bad” to the linter, but the developer understands and intends it to be there for some reason.

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

3

  • 4

    for python linters, it is this statement usually but for other linters it can be different, i.e. javascript w/ jshint is: // jshint ignore:line (jshint.com/docs)

    – jimf

    Jul 28, 2017 at 11:26


  • 9

    It works in PyCharm too. Short form generic # noqa. Or long form specific # noinspection PyUnresolvedReferences for example.

    – Bob Stein

    Oct 16, 2017 at 21:41

  • 10

    Note that for pycodestyle/pep8 # nopep8 can also be used which is a little clearer, imo.

    Mar 6, 2019 at 18:47

118

noqa = NO-QA (NO Quality Assurance)

It’s generally used in Python code to ignore PEP8 warnings.

Lines with #noqa at the end will be ignored by linter programs and won’t raise any warnings.

    85

    You know what? Even Guido van Rossum (the creator of Python) asked this question before 😀

    A bit Etymology of # 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 stuck.

    Some basic usages of # noqa (with flake8):

    • # flake8: noqa: files that contain this line are skipped
    • lines that contain a # noqa comment at the end: will not issue warnings
    • # noqa: <error>, e.g., # noqa: E234 at the end: ignore specific errors on a line
      • multiple error codes can be given, separated by comma
      • the colon before the list of codes is required

    2

    • 4

      this is definitively the best answer! academic, historical, practical, simple.

      – d34n5

      Nov 19, 2020 at 2:18

    • 4

      @d34n5 this is definitely the best comment! comprehensive, lyrical, monolexemic, simple.

      – Bob Stein

      Aug 28, 2021 at 14:56