Python 注释中的“#noqa”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45346575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does '# noqa' mean in Python comments?
提问by Ishpreet
While searching through a Python project, I found a few lines commented with # noqa
.
在搜索 Python 项目时,我发现有几行用# 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?
noqa
在 Python中是什么意思?它仅特定于 Python 吗?
回答by jimf
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.
添加# noqa
到一行表示 linter(自动检查代码质量的程序)不应检查该行。代码可能生成的任何警告都将被忽略。
That line may have something that "looks bad" to the linter, but the developer understands and intends it to be there for some reason.
这条线可能有一些对 linter 来说“看起来很糟糕”的东西,但开发人员理解并打算出于某种原因将它放在那里。
For more information, see the Flake8 documentation for Selecting and Ignoring Violations.
有关更多信息,请参阅有关 Selecting and Ignoring Violations的Flake8 文档。
回答by Vishvajit Pathak
noqa = NO-QA (NO Quality Assurance)
noqa = NO-QA(无质量保证)
It's generally referred in Python Programming to ignore the PEP8warnings.
通常在 Python Programming 中提到忽略PEP8警告。
In simple words, lines having #noqa at the end will be ignored by the linter programs and they won't raise any warnings.
简而言之,以 #noqa 结尾的行将被 linter 程序忽略,并且不会引发任何警告。
回答by YaOzI
You know what? Even Guido van Rossum (the creator of Python) asked this question before:D
你知道吗?甚至 Guido van Rossum(Python 的创造者)之前也问过这个问题: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.
它曾经是“nopep8”,但是当 Flake8 和 Pep8 想要一个共同的限定符时,@florentx 建议使用“NoQA”作为“No Quality Assurance”(iirc)并且它卡住了。
Some basic usagesof # noqa
(with flake8):
# flake8: noqa
: filesthat contain this lineare skipped- linesthat contain a
# noqa
comment at the end: will not issue warnings # noqa: <error>
, e.g.,# noqa: E234
at the end: ignore specific errorson a line- multiple error codes can be given, separated by comma
- the colon before the list of codes is required
# flake8: noqa
:跳过包含这一行的文件- 最后包含
# noqa
注释的行:不会发出警告 # noqa: <error>
,例如,# noqa: E234
最后:忽略一行中的 特定错误- 可以给出多个错误代码,以逗号分隔
- 代码列表前的冒号是必需的