最新版仅支持 Python 3.11.0 及以上,旧环境需装旧版本;拼写检查需额外安装 pylint[spelling] 并装 enchant C 库;第三方库支持不全,常需另装对应插件如 pylint-django
pip install pylintREADME 未说明;仅要求 Python 3.11.0 及以上,纯静态分析,无需 GPU
Python 静态代码分析器,不运行代码就能查错、查代码异味并给出重构建议
Python 静态代码分析工具,检查编码规范(PEP 8)、潜在错误和代码异味,帮你在提交前发现问题。
核心能力
- 基于 astroid 推断节点实际值,识别别名导入后的真实调用
- 检查错误、强制编码规范并发现代码异味
- 内置大量检查,含默认关闭的可配置主观规则
- 支持编写插件扩展自定义检查,并有第三方框架插件生态
- 附带 pyreverse 生成类图与 symilar 查重复代码
容易踩的坑
- 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-initwhen an attribute is assigned inside the setter of an old-style, non-decoratorproperty(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-assignmentwhen a name bound by an earlier target of the same assignment is used by a later target, as ina = b[a] = 0.Closes #5955
-
Fix a
no-memberfalse positive in a comprehension inside a branch that cannot run, such asif 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-assignmentwhen a name bound by a tuple or list target of awithitem is used by a later item of the samewithstatement.Closes #7545
-
Fix false positives such as
not-callable,not-an-iterable,unpacking-non-sequenceandno-memberon the result of a function whose body is only..., like@overloadand.pyistubs. Such calls were inferred as returningNone. This affectedsqlalchemy.func,pydantic.Field, and thetorchfunctions wrapped by_add_docstr, such astorch.linalg.qr.Closes #8138 Closes #9218 Closes #9354 Closes #10087
-
Fix a false positive for
protected-accesswhen a subclass of a subscripted generic base, such asclass Child(Parent[T]), accesses a protected member through that base, such asParent._foo(self).Closes #8600
-
Avoid emitting
unreachablefor ayieldimmediately afterraiseorsys.exit()that marks a function as a generator, matching the existing handling ofreturn.Closes #8909
-
Fix a false positive for
super-init-not-calledin.pyistub files, where every__init__body is...and cannot call the parent's__init__.Closes #9096
-
Fix a false positive for
possibly-used-before-assignmentwhen 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-delegationwhen 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-argumentin.pyistub files, where function bodies are...and cannot use their arguments.Closes #9417
-
Fix a false positive for
used-before-assignmentwhen 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-differandsignature-differsfortyping.overloadstubs. 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-typewhen the bare_variable is reused to discard values of different types.Closes #10374
-
Allow the
__main__module name in thecamelCase,PascalCaseandUPPER_CASEnaming styles without reportinginvalid-name.Closes #10442
-
Fixed a false positive for
unexpected-keyword-argwhen a decorator that returns its argument unchanged is stacked above a decorator accepting**kwargs.Closes #10831
-
Fix
invalid-namefalse positives for module-level all-caps aliases that preserve the name of an external callable.Closes #11012
-
``redef
-
- 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-unpackingwhen 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 awithstatement target or inside a comprehension.Closes #11492
-
Fix a crash when a name bound by a
typestatement (a TypeVar) is used in awithstatement.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 withmetaclass=__annotations__.Closes #11511
-
Fix a crash in the
using-final-decorator-in-unsupported-versioncheck whenimport finalis used.Closes #11521
-
Fix a crash when a plugin passes
confidence=Nonetoadd_message, aspylint-pytestdoes, for a message that is disabled.confidence=Noneis accepted again and meansUNDEFINED, like in pylint 4.0. Passing it explicitly toadd_message,add_ignored_messageorMessagenow emits aDeprecationWarning: it will raise an error in pylint 5.0.Closes #11530
-
- 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
dillon 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
-
- 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=yno longer walks ignored directories such as.venvornode_modules, which took seconds on large trees. The duplicate-code checker andsymilaralso 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
junitoutput format (--output-format=junit), theNO_COLORandFORCE_COLORenvironment variables are respected, and the files to lint can now be set with thefilesoption in the configuration file.New checks:
looping-through-iterator,impossible-comparison,chained-comparison-all-equalandusing-comprehension-unpacking-in-unsupported-version.Running with
--jobsno longer duplicates the messages of extensions or ignores extensions enabled in the configuration.Plugin authors: the
confidenceparameter can no longer beNone, except inis_message_enabled, and theMSG_STATE_*constants are deprecated in favor of theMessageDisableReasonenum.The required
astroidversion is now 4.3.2. See the astroid changelog for additional fixes, features, and performance improvements applicable to pylint.Breaking Changes
-
The
confidenceparameter is no longer nullable on any APIs except foris_message_enabled(whereconfidence=Nonemeans "don't filter by confidence"). The default becameinterfaces.UNDEFINED(an immutable value); the behavior is unchanged unless you were passing an explicitNone. This avoids a runtime check in multiple function to set the default value conditionally.The
constants.MSG_STATE_*integer were replaced by aMessageDisableReasonenum. The old names remain as deprecated aliases pointing at the enum members.MessageDisableReasonis anIntEnumso existing code comparing the return of_get_message_state_scopeto the literal0/1/2keeps working.Refs #11018
New Features
-
Add support for
ignore-pattern-in-long-linesto allow ignoring specific parts of a line when checking line length.Refs #3352
-
Support for the
NO_COLORandFORCE_COLORenvironment variables has been added. When running pylint, the reporter that writes to stdout is switched betweentextandcolorizedaccording 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
junitoutput 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 coverand# pragma: no branch) are no longer counted toward the line length, so a line is not flagged asline-too-longsolely because of such a pragma. This mirrors the existing behaviour for Pylint's own# pylint:pragmas.Closes #1017
-
- 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-lambdawhen 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-argumentin dataclass__new__methods when the arguments are consumed by a generated__init__method.Closes #9843
-
Fix a false positive for
missing-kwoawhen keyword-only arguments are passed through a**kwargsdictionary that is not a literal at the call site, for example one filled withoptions["key"] = valueafter its creation.Closes #10029
-
ungrouped-importsno longer reports imports inside mutually exclusive OS guard branches (if os.name == "nt":/if sys.platform == "win32":), matching the existing behavior forsys.version_infoguards.Closes #10460
Other Bug Fixes
-
A
TypeErrorcrash could occur when checking aforloop 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 theimport-private-nameextension when an annotated assignment's value is an attribute access on a call rooted at a non-Namenode, e.g.x: str = ''().a.Closes #11479
-
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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