为什么默认的pylintrc会有这么多禁用的消息?

时间:2019-03-06 20:05:09

标签: python pylint pylintrc

如果运行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

2 个答案:

答案 0 :(得分:2)

我认为这种默认的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,您可以对python2代码使用pylint来查找诸如redefined-outer-nameline-too-long之类的其他错误内容,而不会为有效的Python2语法和标准库带来烦人的错误和警告电话。

答案 1 :(得分:2)

From the documentation's Frequently Asked Questions...

  

为什么默认情况下禁用一堆消息?

     

pylint确实默认禁用了某些消息,原因可能是   他们容易产生误报,或者他们自以为是   不包含在默认消息中。但是大多数残疾人   消息来自Python 3移植检查器,该检查器已被禁用   默认。需要使用--py3k标志进行特殊激活。