pylint

pylint-devGPL-2.0活跃维护

Python 静态代码分析工具,检查编码规范(PEP 8)、潜在错误和代码异味,帮你在提交前发现问题。

It's not just a linter that annoys you!

v4.1.3发布于 2026-10-11 07:41 UTC5,747star +2 / 7 天1,436fork同步于 2026-11-10 23:36 UTC

怎么上手

由 README 提炼,执行前请确认
pip install pylint
硬件要求按 README 说明

README 未说明;仅要求 Python 3.11.0 及以上,纯静态分析,无需 GPU

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Python 静态代码分析器,不运行代码就能查错、查代码异味并给出重构建议

Python 静态代码分析工具,检查编码规范(PEP 8)、潜在错误和代码异味,帮你在提交前发现问题。

核心能力

  • 基于 astroid 推断节点实际值,识别别名导入后的真实调用
  • 检查错误、强制编码规范并发现代码异味
  • 内置大量检查,含默认关闭的可配置主观规则
  • 支持编写插件扩展自定义检查,并有第三方框架插件生态
  • 附带 pyreverse 生成类图与 symilar 查重复代码

容易踩的坑

最新版仅支持 Python 3.11.0 及以上,旧环境需装旧版本;拼写检查需额外安装 pylint[spelling] 并装 enchant C 库;第三方库支持不全,常需另装对应插件如 pylint-django

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v4.1.3
  1. v4.1.3最新正式版2026-10-11 · 2026-10-11 07:41 UTC

    What's new in Pylint 4.1.3?

    Release date: 2026-10-11

    False Positives Fixed

    • Fixed a false positive for attribute-defined-outside-init when an attribute is assigned inside the setter of an old-style, non-decorator property(fget, fset) call. The decorator form (@property / @x.setter) was already exempted by the fix for #409; the classic call form was not.

      Closes #3325

    • Fix a false positive for used-before-assignment when a name bound by an earlier target of the same assignment is used by a later target, as in a = b[a] = 0.

      Closes #5955

    • Fix a no-member false positive in a comprehension inside a branch that cannot run, such as if sys.platform == "win32": on Linux. Like the rest of the branch, the comprehension is no longer checked for missing members.

      Closes #7240

    • Fix a false positive for used-before-assignment when a name bound by a tuple or list target of a with item is used by a later item of the same with statement.

      Closes #7545

    • Fix false positives such as not-callable, not-an-iterable, unpacking-non-sequence and no-member on the result of a function whose body is only ..., like @overload and .pyi stubs. Such calls were inferred as returning None. This affected sqlalchemy.func, pydantic.Field, and the torch functions wrapped by _add_docstr, such as torch.linalg.qr.

      Closes #8138 Closes #9218 Closes #9354 Closes #10087

    • Fix a false positive for protected-access when a subclass of a subscripted generic base, such as class Child(Parent[T]), accesses a protected member through that base, such as Parent._foo(self).

      Closes #8600

    • Avoid emitting unreachable for a yield immediately after raise or sys.exit() that marks a function as a generator, matching the existing handling of return.

      Closes #8909

    • Fix a false positive for super-init-not-called in .pyi stub files, where every __init__ body is ... and cannot call the parent's __init__.

      Closes #9096

    • Fix a false positive for possibly-used-before-assignment when a lambda uses its parameters, including from a nested lambda, and that name is assigned later in the module.

      Closes #9126

    • Fix a false positive for useless-parent-delegation when a keyword-only parameter is passed to the parent under the same keyword but with a different value.

      Closes #9226

    • Fix a false positive for unused-argument in .pyi stub files, where function bodies are ... and cannot use their arguments.

      Closes #9417

    • Fix a false positive for used-before-assignment when a name assigned with an assignment expression in the condition of a comprehension is used in its element, for example [y for x in data if (y := f(x))].

      Closes #9460

    • Fixed false positive arguments-differ and signature-differs for typing.overload stubs. Overload stubs in a subclass are no longer compared to the overridden method, and an overridden method with overloads is compared through its implementation instead of its first stub.

      Closes #10186 Closes #5264

    • Stop emitting redefined-variable-type when the bare _ variable is reused to discard values of different types.

      Closes #10374

    • Allow the __main__ module name in the camelCase, PascalCase and UPPER_CASE naming styles without reporting invalid-name.

      Closes #10442

    • Fixed a false positive for unexpected-keyword-arg when a decorator that returns its argument unchanged is stacked above a decorator accepting **kwargs.

      Closes #10831

    • Fix invalid-name false positives for module-level all-caps aliases that preserve the name of an external callable.

      Closes #11012

    • ``redef

  2. v4.1.22026-10-02 · 2026-10-02 22:13 UTC
    查看更新说明

    What's new in Pylint 4.1.2?

    Release date: 2026-10-03

    False Positives Fixed

    • Fixed a false positive unbalanced-tuple-unpacking when unpacking a tuple concatenation whose elements have several possible values.

      Fixed by upgrading astroid to 4.3.3.

      Closes #2621

    Other Bug Fixes

    • Fixed a crash when calling __bases__ on a class.

      Fixed by upgrading astroid to 4.3.3.

      Closes #11491

    • Fix a crash (astroid-error) when the class of a called attribute cannot be fully inferred, for example when the attribute is used as a with statement target or inside a comprehension.

      Closes #11492

    • Fix a crash when a name bound by a type statement (a TypeVar) is used in a with statement.

      Closes #11510

    • Fixed a crash (TypeError) in the variables checker when checking a class whose metaclass name binding has no line number, for example a class defined with metaclass=__annotations__.

      Closes #11511

    • Fix a crash in the using-final-decorator-in-unsupported-version check when import final is used.

      Closes #11521

    • Fix a crash when a plugin passes confidence=None to add_message, as pylint-pytest does, for a message that is disabled. confidence=None is accepted again and means UNDEFINED, like in pylint 4.0. Passing it explicitly to add_message, add_ignored_message or Message now emits a DeprecationWarning: it will raise an error in pylint 5.0.

      Closes #11530

  3. v4.1.12026-09-29 · 2026-09-29 21:09 UTC
    查看更新说明

    What's new in Pylint 4.1.1?

    Release date: 2026-09-29

    Other Changes

    • Pylint 4.1.0 could not be uploaded to PyPI, because it required an unreleased version of dill on Python 3.15, and PyPI refuses such a dependency. 4.1.1 is the first 4.1 release available on PyPI, see the 4.1.0 changes below.

      Refs #11495

  4. v4.1.02026-09-29 · 2026-09-29 20:00 UTC
    查看更新说明

    What's new in Pylint 4.1.0?

    Release date: 2026-09-29

    Startup is about 25% faster thanks to lazy imports. The import checker caches its isort configuration, which makes pylint about 17% faster on ansible. Finding the files to lint with --recursive=y no longer walks ignored directories such as .venv or node_modules, which took seconds on large trees. The duplicate-code checker and symilar also received optimizations that result in considerable performance improvements and memory use reduction on larger codebases. For example, pandas analysis went from 20 min to 55 s and pylint does not get OOM-killed when analyzing cpython anymore.

    Python 3.15 support progresses: the unpacking in comprehensions added by PEP 798 no longer raises false positives, and the standard library deprecations of Python 3.15 are followed.

    For CI, there is a new built-in junit output format (--output-format=junit), the NO_COLOR and FORCE_COLOR environment variables are respected, and the files to lint can now be set with the files option in the configuration file.

    New checks: looping-through-iterator, impossible-comparison, chained-comparison-all-equal and using-comprehension-unpacking-in-unsupported-version.

    Running with --jobs no longer duplicates the messages of extensions or ignores extensions enabled in the configuration.

    Plugin authors: the confidence parameter can no longer be None, except in is_message_enabled, and the MSG_STATE_* constants are deprecated in favor of the MessageDisableReason enum.

    The required astroid version is now 4.3.2. See the astroid changelog for additional fixes, features, and performance improvements applicable to pylint.

    Breaking Changes

    • The confidence parameter is no longer nullable on any APIs except for is_message_enabled (where confidence=None means "don't filter by confidence"). The default became interfaces.UNDEFINED (an immutable value); the behavior is unchanged unless you were passing an explicit None. This avoids a runtime check in multiple function to set the default value conditionally.

      The constants.MSG_STATE_* integer were replaced by a MessageDisableReason enum. The old names remain as deprecated aliases pointing at the enum members. MessageDisableReason is an IntEnum so existing code comparing the return of _get_message_state_scope to the literal 0 / 1 / 2 keeps working.

      Refs #11018

    New Features

    • Add support for ignore-pattern-in-long-lines to allow ignoring specific parts of a line when checking line length.

      Refs #3352

    • Support for the NO_COLOR and FORCE_COLOR environment variables has been added. When running pylint, the reporter that writes to stdout is switched between text and colorized according to the requested mode. The order is: NO_COLOR > FORCE_COLOR > --output-format=....

      Closes #3995

    • The dict-init-mutate message now includes a suggested dictionary literal showing how to combine the initialization and subsequent mutations into a single statement.

      Closes #7819

    • Add a built-in junit output format (--output-format=junit) that produces JUnit-compatible XML output for CI/CD integration with Jenkins, Azure DevOps, GitLab CI, and GitHub Actions.

      Closes #9143

    • Trailing pragmas understood by other common tooling (# type: ignore, # pyright: ignore, # noqa, # pragma: no cover and # pragma: no branch) are no longer counted toward the line length, so a line is not flagged as line-too-long solely because of such a pragma. This mirrors the existing behaviour for Pylint's own # pylint: pragmas.

      Closes #1017

  5. v4.0.102026-09-29 · 2026-09-29 15:47 UTC
    查看更新说明

    What's new in Pylint 4.0.10?

    Release date: 2026-09-29

    False Positives Fixed

    • Fix false positives for :ref:unnecessary-lambda when a variable referenced in the called expression is assigned, reassigned, or deleted later in the same scope.

      Closes #8192

    • Fix a false positive for unused-argument in dataclass __new__ methods when the arguments are consumed by a generated __init__ method.

      Closes #9843

    • Fix a false positive for missing-kwoa when keyword-only arguments are passed through a **kwargs dictionary that is not a literal at the call site, for example one filled with options["key"] = value after its creation.

      Closes #10029

    • ungrouped-imports no longer reports imports inside mutually exclusive OS guard branches (if os.name == "nt": / if sys.platform == "win32":), matching the existing behavior for sys.version_info guards.

      Closes #10460

    Other Bug Fixes

    • A TypeError crash could occur when checking a for loop that iterates over a subscript with non-numeric constant bounds or a zero step, e.g. for a, b in {"k": [][0: ""]}.values():.

      Closes #11472

    • Fix a crash (AttributeError: 'ClassDef' object has no attribute 'expr') in the import-private-name extension when an annotated assignment's value is an attribute access on a call rooted at a non-Name node, e.g. x: str = ''().a.

      Closes #11479

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Pylint_

    .. _Pylint: https://pylint.readthedocs.io/

    .. This is used inside the doc to recover the start of the introduction

    .. image:: https://github.com/pylint-dev/pylint/actions/workflows/tests.yaml/badge.svg?branch=main :target: https://github.com/pylint-dev/pylint/actions

    .. image:: https://codecov.io/gh/pylint-dev/pylint/branch/main/graph/badge.svg?token=ZETEzayrfk :target: https://codecov.io/gh/pylint-dev/pylint

    .. image:: https://img.shields.io/pypi/v/pylint.svg :alt: PyPI Package version :target: https://pypi.python.org/pypi/pylint

    .. image:: https://readthedocs.org/projects/pylint/badge/?version=latest :target: https://pylint.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

    .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/ambv/black

    .. image:: https://img.shields.io/badge/linting-pylint-yellowgreen :target: https://github.com/pylint-dev/pylint

    .. image:: https://results.pre-commit.ci/badge/github/pylint-dev/pylint/main.svg :target: https://results.pre-commit.ci/latest/github/pylint-dev/pylint/main :alt: pre-commit.ci status

    .. image:: https://bestpractices.coreinfrastructure.org/projects/6328/badge :target: https://bestpractices.coreinfrastructure.org/projects/6328 :alt: CII Best Practices

    .. image:: https://img.shields.io/ossf-scorecard/github.com/PyCQA/pylint?label=openssf%20scorecard&style=flat :target: https://api.securityscorecards.dev/projects/github.com/PyCQA/pylint :alt: OpenSSF Scorecard

    .. image:: https://img.shields.io/discord/825463413634891776.svg :target: https://discord.gg/qYxpadCgkx :alt: Discord

    What is Pylint?

    Pylint is a static code analyser_ for Python 2 or 3. The latest version supports Python 3.11.0 and above.

    .. _static code analyser: https://en.wikipedia.org/wiki/Static_code_analysis

    Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells_, and can make suggestions about how the code could be refactored.

    .. _code smells: https://martinfowler.com/bliki/CodeSmell.html

    Install

    .. This is used inside the doc to recover the start of the short text for installation

    For command line use, pylint is installed with::

    pip install pylint
    

    Or if you want to also check spelling with enchant (you might need to install the enchant C library <https://pyenchant.github.io/pyenchant/install.html#installing-the-enchant-c-library>_):

    .. code-block:: sh

    pip install pylint[spelling]

    It can also be integrated in most editors or IDEs. More information can be found in the documentation_.

    .. _in the documentation: https://pylint.readthedocs.io/en/latest/user_guide/installation/index.html

    .. This is used inside the doc to recover the end of the short text for installation

    What differentiates Pylint?

    Pylint is not trusting your typing and is inferring the actual values of nodes (for a start because there was no typing when pylint started off) using its internal code representation (astroid). If your code is import logging as argparse, Pylint can check and know that argparse.error(...) is in fact a logging call and not an argparse call. This makes pylint slower, but it also lets pylint find more issues if your code is not fully typed.

    [inference] is the killer feature that keeps us using [pylint] in our project despite how painfully slow it is.
    - `Realist pylint user`_, 2022
    

    .. _Realist pylint user: https://github.com/charliermarsh/ruff/issues/970#issuecomment-1381067064

    pylint, not afraid of being a little slower than it already is, is also a lot more thorough than other linters. There are more checks, including some opinionated ones that are deactivated by default but can be enabled using configuration.

    How to use pylint

    Pylint isn't smarter than you: it may warn you about things that you have conscientiously done or check for some things that you don't care about. During adoption, especially in a legacy project where pylint was never enforced, it's best to start with the --errors-only flag, then disable convention and refactor messages with --disable=C,R and progressively re-evaluate and re-enable messages as your priorities evolve.

    Pylint is highly configurable and permits to write plugins in order to add your own checks (for example, for internal libraries or an internal rule). Pylint also has an ecosystem of existing plugins for popular frameworks and third-party libraries.

    .. note::

    Pylint supports the Python standard library out of the box. Third-party
    libraries are not always supported, so a plugin might be needed. A good place
    to start is ``PyPI`` which often returns a plugin by searching for
    ``pylint <library>``. `pylint-pydantic`_, `pylint-django`_ and
    `pylint-sonarjson`_ are examples of such plugins. More information about plugins
    and how to load them can be found at `plugins`_.
    

    .. _plugins: https://pylint.readthedocs.io/en/latest/development_guide/how_tos/plugins.html#plugins .. _pylint-pydantic: https://pypi.org/project/pylint-pydantic .. _pylint-django: https://github.com/pylint-dev/pylint-django .. _pylint-sonarjson: https://github.com/cnescatlab/pylint-sonarjson-catlab

    Advised linters alongside pylint

    Projects that you might want to use alongside pylint include ruff_ (really fast, with builtin auto-fix and a large number of checks taken from popular linters, but implemented in rust) or flake8_ (a framework to implement your own checks in python using ast directly), mypy_, pyright_ / pylance or pyre_ (typing checks), bandit_ (security oriented checks), black_ and isort_ (auto-formatting), autoflake_ (automated removal of unused imports or variables), pyupgrade_ (automated upgrade to newer python syntax) and pydocstringformatter_ (automated pep257).

    .. _ruff: https://github.com/astral-sh/ruff .. _flake8: https://github.com/PyCQA/flake8 .. _bandit: https://github.com/PyCQA/bandit .. _mypy: https://github.com/python/mypy .. _pyright: https://github.com/microsoft/pyright .. _pyre: https://github.com/facebook/pyre-check .. _black: https://github.com/psf/black .. _autoflake: https://github.com/myint/autoflake .. _pyupgrade: https://github.com/asottile/pyupgrade .. _pydocstringformatter: https://github.com/DanielNoord/pydocstringformatter .. _isort: https://pycqa.github.io/isort/

    Additional tools included in pylint

    Pylint ships with two additional tools:

    • pyreverse_ (standalone tool that generates package and class diagrams.)
    • symilar_ (duplicate code finder that is also integrated in pylint)

    .. _pyreverse: https://pylint.readthedocs.io/en/latest/additional_tools/pyreverse/index.html .. _symilar: https://pylint.readthedocs.io/en/latest/additional_tools/symilar/index.html

    .. This is used inside the doc to recover the end of the introduction

    Contributing

    .. This is used inside the doc to recover the start of the short text for contribution

    We welcome all forms of contributions such as updates for documentation, new code, checking issues for duplicates or telling us that we can close them, confirming that issues still exist, creating issues because you found a bug or want a feature_, etc. Everything is much appreciated!

    Please follow the code of conduct_ and check the Contributor Guides_ if you want to make a code contribution.

    .. _creating issues because you found a bug or want a feature: https://pylint.readthedocs.io/en/latest/contact.html#bug-reports-feedback .. _code of conduct: https://github.com/pylint-dev/pylint/blob/main/CODE_OF_CONDUCT.md .. _the Contributor Guides: https://pylint.readthedocs.io/en/latest/development_guide/contribute.html

    .. This is used inside the doc to recover the end of the short text for contribution

    Show your usage

    You can place this badge in your README to let others know your project uses pylint.

    .. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
        :target: https://github.com/pylint-dev/pylint
    

    Learn how to add a badge to your documentation in the badge documentation_.

    .. _the badge documentation: https://pylint.readthedocs.io/en/latest/user_guide/installation/badge.html

    License

    pylint is, with a few exceptions listed below, GPLv2 <https://github.com/pylint-dev/pylint/blob/main/LICENSE>_.

    The icon files are licensed under the CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/>_ license:

    • doc/logo.png <https://raw.githubusercontent.com/pylint-dev/pylint/main/doc/logo.png>_
    • doc/logo.svg <https://raw.githubusercontent.com/pylint-dev/pylint/main/doc/logo.svg>_

    Support

    Please check the contact information_.

    .. _the contact information: https://pylint.readthedocs.io/en/latest/contact.html

    .. |tideliftlogo| image:: https://raw.githubusercontent.com/pylint-dev/pylint/main/doc/media/Tidelift_Logos_RGB_Tidelift_Shorthand_On-White.png :width: 200 :alt: Tidelift

    .. list-table:: :widths: 10 100

      • |tideliftlogo|
      • Professional support for pylint is available as part of the Tidelift Subscription_. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

    .. _Tidelift Subscription: https://tidelift.com/subscription/pkg/pypi-pylint?utm_source=pypi-pylint&utm_medium=referral&utm_campaign=readme