为什么默认的 pylintrc 有这么多禁用消息?
Why does the default pylintrc have so many disabled messages?
如果您 运行 pylint --generate-rcfile > pylintrc
并查看默认的 rc 文件,您将看到以下禁用警告列表。
为什么默认禁用它们?
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating
我认为这样的默认 rc 文件旨在将 pylint 应用于 python2 代码,而不会出现大量错误和警告。注意:大部分禁用语句属于 python2 语法和标准库 api:
- print-statement -
print
在 Python2 中是一个语句,在 Python3 中它是一个函数
- old-raise-syntax -
except Exception, e
语法对 Python3 无效,在 Python3 中 except Exception as e
仅有效
- xrange-builtin -
xrange
替换为 range
- 等等
因此,使用此默认 rc,您可以将 pylint 用于 python2 代码,以找出 redefined-outer-name
、line-too-long
和其他不好的东西,而不会收到恼人的错误和警告有效的 Python2 语法和标准库调用。
From the documentation's Frequently Asked Questions...
Why are there a bunch of messages disabled by default?
pylint does have some messages disabled by default, either because
they are prone to false positives or that they are opinionated enough
for not being included as default messages. But most of the disabled
messages are from the Python 3 porting checker, which is disabled by
default. It needs special activation with the --py3k flag.
如果您 运行 pylint --generate-rcfile > pylintrc
并查看默认的 rc 文件,您将看到以下禁用警告列表。
为什么默认禁用它们?
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating
我认为这样的默认 rc 文件旨在将 pylint 应用于 python2 代码,而不会出现大量错误和警告。注意:大部分禁用语句属于 python2 语法和标准库 api:
- print-statement -
print
在 Python2 中是一个语句,在 Python3 中它是一个函数 - old-raise-syntax -
except Exception, e
语法对 Python3 无效,在 Python3 中except Exception as e
仅有效 - xrange-builtin -
xrange
替换为range
- 等等
因此,使用此默认 rc,您可以将 pylint 用于 python2 代码,以找出 redefined-outer-name
、line-too-long
和其他不好的东西,而不会收到恼人的错误和警告有效的 Python2 语法和标准库调用。
From the documentation's Frequently Asked Questions...
Why are there a bunch of messages disabled by default?
pylint does have some messages disabled by default, either because they are prone to false positives or that they are opinionated enough for not being included as default messages. But most of the disabled messages are from the Python 3 porting checker, which is disabled by default. It needs special activation with the --py3k flag.