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

2024-06-16 08:32:58 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: importrawnotmethodolddictlongdeprecated
2条回答

我认为这样的默认rc文件是为了将pylint应用于python2代码而设计的,不会出现大量的错误和警告。注意:大多数被禁用的语句属于python2语法和标准库api:

  • print语句-print在Python2中是一个语句,在Python3中它是一个函数
  • 旧的raise语法-Python3中存在对Python3无效的except Exception, e语法except Exception as e仅有效
  • xrange内置-xrange被替换为range
  • 等等

因此,使用这个默认的rc,您可以使用pylint for python2代码来查找诸如redefined-outer-nameline-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.

相关问题 更多 >