What does '# noqa' mean in Python comments?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Meditation
--
Chapters
00:00 What Does '# Noqa' Mean In Python Comments?
00:19 Accepted Answer Score 433
00:47 Answer 2 Score 155
01:06 Answer 3 Score 128
01:57 Answer 4 Score 33
03:35 Answer 5 Score 0
03:48 Thank you
--
Full question
https://stackoverflow.com/questions/4534...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #comments #terminology #codeanalysis #pep8
#avk47
ACCEPTED ANSWER
Score 436
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.
ANSWER 2
Score 157
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.
ANSWER 3
Score 129
You know what? Even Guido van Rossum (the creator of Python) asked this question before :D
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 
# noqacomment at the end: will not issue warnings # noqa: <error>, e.g.,# noqa: E234at 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
 
ANSWER 4
Score 33
Came here after finding a # noqa directive in a library that I was working with. Having never heard of it, I naturally arrived here after searching on Google. The answers provided here are adequate but I wanted to provide some further elaboration for those that may be curious (I certainly was)
# noqahas evolved from the# nopep8syntax used in previous releases of flake8# noqais supported by IDEs, like PyCharm, for use with their built-in code inspection tools.# noqacan be used as a pre-commit directive, such that prior to new commits an inspection process must complete# noqacan be used to ignore all warnings or given specific warnings to ignore. For example,# noqa: F401will ignore an unused imported module warning.
As an example, consider the following code:
import os
print("Hello, world!")
This code imports the os module but doesn't use it. If one wanted to use the # noqa tool to suppress a PEP8 warning, it could be written as such:
import os  # noqa
print("Hello, world!")
This will ignore all warnings. However, if one were only to want to ignore a specific warning (PEP8 F401 imported but not used), it could be done as such:
import os  # noqa: F401
print("Hello, world!")
I've published an article with some noqa examples and more elaboration on the above points.