*************************** What's New in Pylint 4.1 *************************** .. toctree:: :maxdepth: 2 :Release:4.1 :Date: TBA Summary -- Release highlights ============================= The duplicate-code checker and ``symilar`` 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. The required ``astroid`` version is now 4.3.1. See the `astroid changelog `_ for additional fixes, features, and performance improvements applicable to pylint. .. towncrier release notes start What's new in Pylint 4.0.0-dev0? -------------------------------- Release date: TBA 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 (`#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 (`#3352 `_) - 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 (`#7819 `_) - 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 #10172 (`#10172 `_) - pyreverse: add ``--no-signatures`` to show method names without parameter lists or return type annotations in class diagrams. Closes #10772 (`#10772 `_) - Add support for `--known-first-party` similar to `--known-third-party`. Refs #10803 (`#10803 `_) New Checks ---------- - Add new checks ``impossible-comparison`` and ``chained-comparison-all-equal``. ``impossible-comparison`` flags boolean conditions whose chain of numeric comparisons is logically contradictory and can never be true (for example ``a > b and b > a``). ``chained-comparison-all-equal`` flags boolean conditions whose operands form a cycle of weak inequalities (``<=`` or ``>=``) and can be simplified to a chain of equalities (for example ``a >= b and b >= a`` is equivalent to ``a == b``). Closes #5814 (`#5814 `_) - Add ``using-comprehension-unpacking-in-unsupported-version`` (W2607), emitted when the code uses the unpacking in comprehensions added by PEP 798 while ``py-version`` still includes a Python version that cannot compile it. Refs #10982 (`#10982 `_) False Positives Fixed --------------------- - Fix false positives for :ref:`attribute-defined-outside-init` where ``__init__`` (etc.) uses a helper method to create attributes. Closes #5214 (`#5214 `_) - ``implicit-str-concat`` is no longer emitted for an implicit concatenation of a raw string with a non-raw one (e.g. ``r"\d" "\n"``). Such literals cannot be merged into a single string, so the concatenation is intentional rather than a forgotten comma. Closes #6663 (`#6663 `_) - Fix a false positive for ``consider-using-generator`` and ``use-a-generator`` with an asynchronous list comprehension. Turning it into a generator expression would create an asynchronous generator, which those functions cannot consume. Closes #7271 (`#7271 `_) - Fix a false positive for :ref:`not-callable` when calling functions constructed with ``types.FunctionType`` or ``types.LambdaType``. Closes #7500 (`#7500 `_) - Fixed a false positive ``assigning-non-slot`` when assigning to an inherited descriptor through an instance returned by a method annotated with the subclass. This regressed in pylint 3.0.0. Fixed by upgrading astroid to 4.1.0. Closes #8053 (`#8053 `_) - Fix a false positive for ``invalid-name`` (C0103) where the default ``typevar-rgx`` rejected ``TypeVar`` names containing digits, such as ``Ec2T``. Closes #8499 (`#8499 `_) - Fix a false positive for ``too-many-arguments`` in (non-static) methods and classmethods. Closes #8675 (`#8675 `_) - Fixed a false positive ``no-member`` when a ``classmethod`` annotated with ``typing.Self`` is overridden in a subclass and its result is used directly, as in ``Subclass.build().only_on_subclass()``. The return type is now narrowed to the subclass rather than the base class. This regressed in pylint 3.0.0. Fixed by upgrading astroid to 4.1.0. Closes #9159 (`#9159 `_) - Fix a false positive for ``unnecessary-direct-lambda-call`` when a directly called lambda in a class body wraps a comprehension containing an assignment expression. PEP 572 makes that a ``SyntaxError`` without the lambda's scope, so following the message produced code that would not compile. Closes #9294 (`#9294 `_) - Fix a false positive for :ref:`unnecessary-ellipsis` when an ellipsis is the sole body statement of a method defined on a ``Protocol``. Closes #9319 (`#9319 `_) - Avoid emitting ``deprecated-class`` for imports inside a recognized ``sys.version_info`` guard. Closes #9533 (`#9533 `_) - Fix a false positive for ``inconsistent-return-statements`` when an instance method annotated with ``NoReturn`` (or ``Never``) is called via the class rather than an instance (e.g. ``MyClass.raise_method(obj)``). The unbound method form is now recognised as never returning, matching the existing behaviour for the bound-method form. Closes #9692 (`#9692 `_) - Fix a false positive for ``no-member`` when a value is inferred to several possible types and at least one of them defines a dynamic ``__getattr__``. Closes #9833 (`#9833 `_) - Fix ``used-before-assignment`` false positive for names bound in only some arms of an ``if/elif/else`` chain. Closes #9879 (`#9879 `_) - Fix a false positive for ``useless-parent-delegation`` when a method overrides a method of a C-level parent whose signature cannot be inspected, such as ``Exception.__init__``. Because ``Exception.__init__`` accepts ``*args``, an override taking only ``self`` narrows the accepted arguments and is not useless. Overrides of ``object.__init__`` are still reported. Closes #9994 (`#9994 `_) - Fixed a false positive ``no-name-in-module`` when a module is imported with an alias that shadows its base module and a function named ``format`` is called on the alias. Fixed by upgrading astroid to 4.3.1. Closes #10193 (`#10193 `_) - Fix a false positive for :ref:`unspecified-encoding` when an ``open`` call uses a mode argument that cannot be inferred. Closes #10201 (`#10201 `_) - Fixed a false positive ``unexpected-keyword-argument`` when passing ``dtype`` to ``numpy.concatenate()``. Fixed by upgrading astroid to 4.3.1. Closes #10548 (`#10548 `_) - Fix a false positive for ``function-redefined`` (E0102) when reusing names that match ``dummy-variables-rgx`` (such as ``_``), which is common for ``pytest-bdd`` step definitions. This restores the behavior from before pylint 4.0.0; as a consequence the false negative fixed in #9894 is reintroduced for functions whose name matches ``dummy-variables-rgx``. Closes #10665 (`#10665 `_) - Fix a false positive for ``unexpected-keyword-arg`` for dataclasses using generic type aliases (PEP 695). Closes #10703 (`#10703 `_) - Fix possibly-used-before-assignment false positive when using self.fail() in tests. Closes #10743 (`#10743 `_) - Fixed false positive for ``logging-unsupported-format`` when no arguments are provided to logging functions. According to Python's logging documentation, no formatting is performed when no arguments are supplied, so strings like ``logging.error("%test")`` are valid. Closes #10752 (`#10752 `_) - Fix a false positive for ``invalid-name`` (C0103) on names assigned in an ``if __name__ == "__main__":`` block. Such a block reads like a script body, so a name there is now accepted if it matches either the constant or the variable naming style. Closes #10766 (`#10766 `_) - Fix false positive ``unreachable`` when calling a function with ``@overload`` where one signature returns ``NoReturn``. Closes #10785 (`#10785 `_) - Fix a false positive for ``too-many-function-args`` for dataclasses using generic type aliases (PEP 695). Closes #10788 (`#10788 `_) - Fix a false positive for ``invalid-name`` where a dataclass field typed with ``Final`` was evaluated against the ``class_const`` regex instead of the ``class_attribute`` regex. Closes #10790 (`#10790 `_) - Avoid emitting `unspecified-encoding` (W1514) when `py-version` is 3.15+. Refs #10791 (`#10791 `_) - Fix a false positive ``relative-beyond-top-level`` error when linting specific files in namespace packages in parallel mode by augmenting ``sys.path`` before loading plugins and expanding files consistently for parallel workers. Closes #10794 (`#10794 `_) - Fix ``undefined-variable`` false positive when a name used as a ``metaclass`` argument in a nested class is referenced again later in the module. Closes #10823 (`#10823 `_) - Fix a false positive for ``unused-variable`` where global variables matching ``dummy-variables-rgx`` were still reported as unused when ``allow-global-unused-variables`` was disabled. Closes #10890 (`#10890 `_) - Fix ``# pylint: enable`` inside a ``try`` block leaking into the ``except`` handler. For example in the following code, ``no-member`` is no longer incorrectly re-enabled in the ``except`` block: .. code-block:: python class Basket: # pylint: disable=no-member def pick(self): try: # pylint: enable=no-member print(self.apple) # no-member emitted here except KeyError: print(self.banana) # no-member NOT emitted here (correct) Requires astroid 4.2. Refs #10933 (`#10933 `_) - Fix a false positive for ``bad-dunder-name`` when there is a user-defined ``__suppress_context__`` attribute on exception subclasses. Closes #10960 (`#10960 `_) - Fix ``used-before-assignment`` false positive for names bound by ``from X import *`` in every branch of an ``if``/``elif``/``else`` chain. Refs #10980 (`#10980 `_) - Fix false positives for the Python 3.15 syntax added by PEP 798, unpacking in comprehensions: - ``star-needs-assignment-target`` (E0114) was emitted for the unpacked element of a comprehension, e.g. ``[*sub for sub in lists]``. - ``consider-using-dict-comprehension`` (R1717) was emitted for ``dict([*pairs for pairs in nested])``, which flattens its argument and is therefore not equivalent to a key/value dict comprehension. Refs #10982 (`#10982 `_) - Fix ``access-member-before-definition`` false positive for bare type annotations (``self.x: Type``) that don't assign a value. Refs #11015 (`#11015 `_) - Check for metaclass __call__ signature when evaluating arguments of a class call. Closes #11032 (`#11032 `_) - Fix false positive ``method-hidden`` when ``cached_property`` is imported directly with ``from functools import cached_property``. Refs #11037 (`#11037 `_) - Fix a false positive for ``assignment-from-no-return`` when the called function's body ends in an unconditional ``raise``, such as ``pathlib.Path.readlink()`` on platforms without symlink support. Closes #11114 (`#11114 `_) - Fix a false positive for ``protected-access`` when a protected member is accessed through ``self.__class__``, which is now treated like ``type(self)``. Closes #11160 (`#11160 `_) - Fix a false positive for ``invalid-name`` when a module-level variable is assigned an instance of a ``TypedDict`` subclass. Such a name is a value, not a type definition, so it is now checked against the constant or variable regex instead of ``class-rgx``. Closes #11231 (`#11231 `_) - Treat ``typing.NoReturn`` and ``typing.Never`` the same as ``NoReturn`` / ``Never`` when deciding that a call never returns. Closes #11271 (`#11271 `_) - Fix false positives for :ref:`invalid-str-returned`, :ref:`invalid-repr-returned`, :ref:`invalid-format-returned`, :ref:`invalid-bytes-returned`, :ref:`invalid-hash-returned`, :ref:`invalid-index-returned`, :ref:`invalid-length-returned`, :ref:`invalid-length-hint-returned`, :ref:`invalid-getnewargs-returned` and :ref:`invalid-getnewargs-ex-returned` when the returned value is an instance of a subclass of the expected builtin type, such as ``self`` in a ``str`` subclass or a ``namedtuple``. Closes #11306 (`#11306 `_) - Fix a false positive for :ref:`unreachable` on the statement following an instantiation of ``_sitebuiltins.Quitter`` (the class of the ``exit`` and ``quit`` builtins). Only calling the instance terminates, not creating it. Closes #11310 (`#11310 `_) - Fix false positives for :ref:`bad-string-format-type` when the argument is an instance of a subclass of ``int``, ``float`` or ``str``, such as ``bool`` or an ``IntEnum`` member formatted with ``%d``. Closes #11315 (`#11315 `_) - Fix a false positive for :ref:`bad-exception-cause` when the bases of the class being raised from cannot be inferred, such as an exception deriving from a C extension class. :ref:`raising-non-exception` and :ref:`catching-non-exception` already guard the same ``inherit_from_std_ex`` helper with ``has_known_bases``. Refs #11399 (`#11399 `_) False Negatives Fixed --------------------- - ``missing-param-doc`` and ``missing-type-doc`` no longer false-negative on NumPy-style parameters whose type line includes a default value, e.g. ``number : int, default 0``. Any text after the colon on the type line is now accepted as the type, matching the NumPy style guide. Closes #6211 (`#6211 `_) - The ``docparams`` extension now emits ``multiple-constructor-doc`` when constructor parameters are documented in both the class docstring and the constructor docstring, even when the constructor method is skipped by ``no-docstring-rgx``. Closes #6692 (`#6692 `_) - ``chained-comparison`` is now emitted for additional simplifiable patterns (e.g. ``a > 1 and a > 10``) and its message now includes the suggested simplification. Refs #7611 (`#7611 `_) - Fix a false negative for ``abstract-method`` where a concrete subclass inheriting from an abstract class (without redeclaring ``abc.ABC`` or ``ABCMeta``) was treated as abstract and silently exempted from the check. A class is now only considered abstract when it opts in explicitly, via direct ``abc.ABC`` inheritance, ``metaclass=ABCMeta``, an ``@abstractmethod`` defined on the class, or being a ``Protocol``. Closes #7950 (`#7950 `_) - :ref:`attribute-defined-outside-init` now reports attributes assigned with ``setattr(self, "name", value)`` outside defining methods. It no longer reports attributes assigned normally when a defining method of the class or of a parent initializes them with ``setattr``. Closes #9798 (`#9798 `_) - ``superfluous-parens`` (``C0325``) no longer false-negatives on a single parenthesised literal after the ``in`` keyword, e.g. ``x in ("foo")``. The parentheses around a single string or number literal are now reported as superfluous, while a tuple (``x in ("foo",)``) or a larger expression (``x in ("foo" + bar)``) is still left untouched. Closes #9878 (`#9878 `_) - ``comparison-with-itself`` now detects repeated attribute chains such as ``object.attribute == object.attribute``. Closes #10713 (`#10713 `_) - ``not-an-iterable`` and ``not-a-mapping`` are now also emitted for the value unpacked by PEP 798 comprehension unpacking, e.g. ``[*number for number in numbers]`` or ``{**number for number in numbers}``. Refs #10982 (`#10982 `_) - Fix a false negative in ``unnecessary-negation`` (``C0117``): ``not (a is not b)`` and ``not (a not in b)`` are now flagged (they simplify to ``a is b`` and ``a in b``), consistent with the existing handling of ``is`` / ``in``. Closes #11140 (`#11140 `_) - Emit ``arguments-differ`` when an overridden special method takes a different number of parameters. Only renamed parameters and removed variadics stay exempt, and the constructor family (``__new__``, ``__init__``, ``__init_subclass__`` and ``__post_init__``) is still fully ignored. Closes #11295 (`#11295 `_) - ``redundant-unittest-assert`` now also flags ``assertEqual`` and ``assertNotEqual`` when both compared values are constants, e.g. ``self.assertEqual(5, 5)``. Closes #11321 (`#11321 `_) - Fix a false negative for ``unspecified-encoding`` and ``bad-open-mode`` when the mode of an ``open`` call is a parameter of the enclosing function that has a default value. The default is now used to check the call, as a literal mode would be. Calls with such a mode stopped being reported in pylint 4.0.8. Refs #11415 (`#11415 `_) Other Bug Fixes --------------- - ``# pylint: disable`` comments at the beginning of an ``else`` block (or on the line just above the ``else`` keyword) now suppress messages in that block instead of being ignored. Fixed by upgrading astroid to 4.3.1. Closes #872 (`#872 `_) - ``dangerous-default-value`` now detects mutable default values in ``typing.NamedTuple`` field definitions. Closes #3716 (`#3716 `_) - Repeated ``--output-format`` options now write reports to every requested file instead of only the last one. Closes #8147 (`#8147 `_) - Fix the suggestion of ``unnecessary-comprehension`` for a dict comprehension that iterates a dict directly, e.g. ``{a: b for a, b in d}``. Iterating a dict yields its keys, so the suggestion is now ``dict(d.keys())`` instead of the incorrect ``dict(d)``, which would simply copy ``d``. Closes #8256 (`#8256 `_) - Fixed a crash when defining a functional ``namedtuple`` with a field name that changes under NFKC normalization, like ``"ยต"`` (MICRO SIGN). Fixed by upgrading astroid to 4.3.1. Closes #8746 (`#8746 `_) - Fix a crash in ``pyreverse`` when a requested class cannot be inferred. Closes #9797 (`#9797 `_) - Fix a false positive for ``declare-non-slot`` when a class variable is annotated with ``ClassVar`` without an initial value. Closes #9950 (`#9950 `_) - Fix enabling checks from extensions which are disabled by default if multiple jobs are used. Closes #10037 (`#10037 `_) - Fix a crash in ``consider-using-enumerate`` when the ``for`` loop target is an attribute (e.g. ``for self.idx in range(len(x))``) rather than a simple variable name. Closes #10099 (`#10099 `_) - Fixed an ``AstroidBuildingError`` crash when inheriting from a generic dataclass that rebinds ``__init__`` in ``__init_subclass__``. Fixed by upgrading astroid to 4.3.1. Closes #10519 (`#10519 `_) - ``wrong-import-position`` now exempts ``try``, ``if``, ``with``, and ``match`` blocks from marking the import boundary. Fixed ``async def`` not being detected as an import boundary. Pragma on non-import lines now suppresses following imports until the next non-import. Closes #10589 (`#10589 `_) - Fix duplicate messages for extension checks if multiple jobs are used. Refs #10642 (`#10642 `_) - Fix `--known_third_party` config being ignored. Closes #10801 (`#10801 `_) - Fixed dynamic color mapping for "fail-on" messages when using multiple reporter/output formats. Closes #10825 (`#10825 `_) - dependency on isort is now set to <9, permitting to use isort 8. Closes #10857 (`#10857 `_) - Fix crash when checking ``attribute-defined-outside-init`` on classes that inherit from a base class pylint cannot fully analyze. Closes #10892 (`#10892 `_) - Fix an issue where discovery can miss a similarly named directory if a shorter named directory is processed first. Closes #10969 (`#10969 `_) - Follow the standard library deprecations of Python 3.15. Refs #10982 (`#10982 `_) - Fixed inflated message occurrence counts in the final ``Messages`` report when running pylint in parallel mode with ``--jobs`` greater than 1. Closes #10996 (`#10996 `_) - Fix ``add_message`` silently overwriting an explicit ``col_offset=0`` (or any other zero-valued ``line``/``end_lineno``/``end_col_offset``) with the AST node's value. The internal ``_add_one_message`` helper used a falsey check (``if not col_offset:``) to detect an omitted argument, which incorrectly treated a legitimate ``0`` the same as ``None``. It now uses an identity check against ``None``. Refs #11020 (`#11020 `_) - Fix a crash in the name checker when a non-constant value is passed as the ``covariant`` or ``contravariant`` argument of a ``TypeVar``. Closes #11022 (`#11022 `_) - Fix a crash in the variable checker when a name resolves to a dataclass-synthesized ``__init__``, which has no line number. Closes #11023 (`#11023 `_) - Fix a crash in the variables checker when ``NotImplemented`` is used as the test of an ``if`` statement, which raised a ``TypeError`` in a boolean context on Python 3.14. Closes #11025 (`#11025 `_) - Avoided a crash from the implicit booleaness checker for ``len()`` calls without arguments. Closes #11028 (`#11028 `_) - Fix a crash in the variables checker when a class declares a metaclass whose attribute-access chain does not bottom out at a name (e.g. ``class C(metaclass=None._)``). Originally reported as ``pylint-dev/astroid#3066``. Refs #11031 (`#11031 `_) - Fix a crash in the name checker when a chained assignment of a ``TypeAlias`` value has a non-name target such as a ``Subscript`` (for example ``a[0] = b = TypeAlias``). Closes #11056 (`#11056 `_) - Fix a crash in the deprecated checker when ``__import__`` is called with a non-string constant argument (for example ``__import__(1)``). Closes #11059 (`#11059 `_) - Avoid crashing when enum member inference fails while checking enum subclasses. Closes #11069 (`#11069 `_) - Prevent a crash in ``unexpected-keyword-arg`` analysis when ``infer_call_result()`` raises ``InferenceError`` while inspecting decorator return signatures. Closes #11070 (`#11070 `_) - Fix a crash in the typecheck checker when a class uses a non-class object (for example a function) as its ``metaclass=`` argument. Closes #11071 (`#11071 `_) - Allow digits in ParamSpec and TypeVarTuple names for `invalid-name` check. The default `paramspec-rgx` and `typevartuple-rgx` patterns rejected names containing digits (e.g. ``Ec2P``, ``S3Ts``), emitting a false ``invalid-name`` (C0103). Allow digits in the lowercase segments, consistent with the ``typevar`` and ``typealias`` patterns. Closes #11090 (`#11090 `_) - Fix a crash in the ``bad-open-mode`` check when the ``mode`` argument of ``open`` is the ``NotImplemented`` constant (Python >= 3.14). Closes #11099 (`#11099 `_) - Fix a crash in the ``not-context-manager`` and ``not-async-context-manager`` checks when the context manager infers to a value without a name, such as the ``slice`` returned by ``with slice(...)`` / ``async with slice(...)``. Closes #11102 (`#11102 `_) - Fix a false positive for ``nested-min-max`` (``W3301``) when the inner ``min``/``max`` call carries a keyword argument such as ``key=``. Flattening the call dropped the keyword and changed the result, so nested calls whose inner call has keyword arguments are no longer flagged. Closes #11130 (`#11130 `_) - Fix a false suggestion from ``nested-min-max`` (``W3301``): when rewriting a nested ``min``/``max`` into a splat call, arguments positioned after the splatted call were silently dropped, so the suggested code changed the result. Closes #11134 (`#11134 `_) - Fix a false positive for ``too-many-locals`` (``R0914``): PEP 695 type parameters, i.e. the ``T1`` and ``T2`` in a generic ``def f[T1, T2]`` signature, were counted as local variables. They are type-system constructs, not runtime locals, and are now excluded from the local-variable count. Closes #11136 (`#11136 `_) - Fix `literal-comparison` (`R0123`) emitting a corrupted suggestion for identifiers that contain ``is`` (e.g. ``axis is 5`` was rendered ``ax== == 5``). The suggestion is now rebuilt from the operands and operator. Closes #11146 (`#11146 `_) - Fix false positives in `bad-string-format-type` (`E1307`) for valid ``%`` formatting: ``%i``/``%u`` applied to a float (both truncate like ``%d``) and ``%a`` applied to any non-int type (``%a`` is type-agnostic like ``%s``/``%r``). Closes #11147 (`#11147 `_) - Fix a false positive for :ref:`useless-parent-delegation` when an override changes the default value of a positional-only parameter. Closes #11148 (`#11148 `_) - Fix a crash in ``consider-using-dict-items`` when the ``for`` loop or comprehension target is an attribute or a subscript (e.g. ``for self.key in d``) rather than a simple variable name. Closes #11173 (`#11173 `_) - Fixed a crash in ``comparison-with-callable`` when comparing a lambda assigned as a class attribute. Closes #11175 (`#11175 `_) - ``too-many-lines`` could be reported at the line of a ``# pylint: disable=too-many-lines`` pragma found in a previously linted module. Pragma positions are now reset between modules, so the message is reported at line 1 (or at the current module's own pragma) regardless of which files were linted before. Refs #11191 (`#11191 `_) - ``nan-comparison`` now also recognizes ``math.nan``, ``numpy.nan``, ``Decimal("nan")`` and any name or attribute that pylint can infer to a NaN constant, such as a module level constant defined as ``math.nan``. Only ``numpy.NaN`` -- removed in numpy 2.0 -- and ``float("nan")`` were detected before. Infinities are still not reported, as comparing against them is meaningful. Refs #11219 (`#11219 `_) - Fix a crash when a call unpacks a dictionary whose keys are not string constants, e.g. ``copy.copy(**{-1: 1})``. Closes #11222 (`#11222 `_) - Fix a crash in the comparison checker when a NaN comparison operand is a call to a name that cannot be inferred, such as ``1 == b('nan')``. Closes #11224 (`#11224 `_) - Fix a crash in the ``docparams`` extension when a raised name does not infer to an exception, such as ``raise sum`` or ``raise some_module``. Such objects have no ``ancestors()``, which aborted the whole file with an ``astroid-error`` fatal message. Closes #11228 (`#11228 `_) - Fix a crash in :ref:`invalid-class-object` and :ref:`assigning-non-slot` when ``__class__`` is assigned outside a simple assignment (e.g. ``for obj.__class__ in classes:``). Closes #11267 (`#11267 `_) - Avoid a fatal :ref:`astroid-error` in :ref:`invalid-name`, :ref:`stop-iteration-return`, :ref:`assigning-non-slot` and :ref:`redefined-slots-in-subclass` for classes with duplicate or inconsistent bases, which leave the class without an MRO to walk. Refs #11272 (`#11272 `_) - Fix a crash in the ``use-yield-from`` checker (``AttributeError: 'Subscript' object has no attribute 'name'``) when a loop target is a subscript, attribute, or tuple. Closes #11286 (`#11286 `_) - Fix a crash in the ``docparams`` extension (``AttributeError: 'AssignName' object has no attribute 'decorators'``) when a class has non-function attributes sharing the name of a property setter. Closes #11287 (`#11287 `_) - Fix a crash in the ``unnecessary-default-type-args`` check when a ``Generator`` or ``AsyncGenerator`` subscript holds an empty tuple, such as ``Generator[()]``. Closes #11357 (`#11357 `_) - ``collections.abc.Callable`` and ``collections.abc.Buffer`` no longer count towards ``too-many-ancestors``. Every other abstract base class in ``collections.abc`` was already ignored, so a class deriving from ``Callable`` was charged for an ancestor while an otherwise identical class deriving from ``Iterable`` was not. Refs #11358 (`#11358 `_) Other Changes ------------- - Clarify how to choose the Python interpreter and ``py-version`` when linting a project that supports multiple Python versions. Closes #5038 (`#5038 `_) - You can now set the ``files`` option in configuration files and on the command line. Passing files without the ``--files`` flag is still supported. This allows to set ``files`` to ``files = my_source_directory`` and invoking ``pylint`` with only the ``pylint`` command similar to how other CLI tools allow to do so. The help message can always be invoked with ``pylint -h`` or ``pylint --help``. Closes #5701 (`#5701 `_) - Removed messages (such as ``print-statement`` or ``apply-builtin``) now have their own page in the documentation, with a link to the change that removed them. They are also listed in the messages overview alongside renamed messages. Closes #6670 (`#6670 `_) - Documentation for options defined by ``Run``, such as ``--errors-only`` and ``--init-hook``, is now generated alongside checker configuration options. Closes #6938 (`#6938 `_) - Document that the ``wrong-import-order`` (C0411) classification of imports as third-party vs first-party depends on the current working directory and recommend ``known-first-party`` as the deterministic workaround. Closes #8801 (`#8801 `_) - Clarify related ``no-else-*`` messages so they say that only the first ``elif`` after the reported branch should change. Expand the ``no-else-return`` documentation to explain later branches and when retaining an ``elif`` chain can better communicate an exhaustive decision. Closes #9274 (`#9274 `_) - ``assignment-from-no-return`` now names the callable that does not return anything and, for functions listed in the new ``known-side-effects-only-functions`` option, hints at the equivalent function to use instead (e.g. ``reversed(...)`` for ``reverse()``). Closes #10383 (`#10383 `_) - Upgrade the ``isort`` upper bound so ``isort`` 9 can be installed alongside pylint. Closes #11351 (`#11351 `_) Internal Changes ---------------- - Add ``assertDoesNotAddMessages`` to ``CheckerTestCase`` to assert that specific messages are not emitted, while allowing other messages to be present. This complements ``assertNoMessages`` which asserts that no messages at all are emitted. Refs #9598 (`#9598 `_) - The primer now pairs residual messages โ€” first by ``(symbol, path, obj)`` and then by exact source location โ€” and reports altered messages as a single *changed* entry with a compact diff, rather than as a separate removal + addition. The location-based pass also catches symbol renames at the same code position (e.g. ``used-before-assignment`` โ†’ ``possibly-used-before-assignment``). When several messages are eligible, the one closest to the original line wins, so pairs never cross. New messages are classified into fixed false positives (``useless-suppression``), ``astroid-error`` fatal errors, and the rest. ``astroid-error`` messages are excluded from pairing (their text embeds a unique crash-report path) so persistent crashes keep raising the prominent warning. Truncated comments are now cut at a line break and keep their code fences and ``
`` blocks closed. Refs #10914 (`#10914 `_) - The primer's project cache key is now derived from the commits pinned in ``packages_to_prime.json`` instead of the remote branch tips. ``main`` and PR primer runs now share the same project cache and lint files in the same on-disk order, removing spurious diffs from primer comments (message positions and astroid inference results depend on the order in which modules are linted). Closes #11192 (`#11192 `_) Performance Improvements ------------------------ - Lazily import ``isort``, ``dill``, ``multiprocessing``/``concurrent.futures``, and ``tomlkit`` so they are only loaded when actually needed. This reduces startup time by ~25% (e.g. ``--version``: 91 => 67 ms, ``--help``: 176 => 133 ms, single-file lint: 272 => 226 ms). Closes #2866 (`#2866 `_) - The duplicate-code checker no longer runs when its message (R0801) is disabled, even if ``reports=yes`` is set. Previously, the checker's report (RP0801) would cause the expensive similarity computation to run regardless. Closes #3443 (`#3443 `_) - Sped up the ``duplicate-code`` checker. When run inside pylint the checker now reuses the already-parsed AST instead of re-parsing every file like it has to do when launched via ``symilar``, and it uses a rolling hash window with caching across file pairs. Additionally, a quadratic blow-up in the hash-matching phase is avoided by switching algorithm at a threshold, which previously caused the checker to hang on files with many repeated lines. Speedup scales with codebase size from 1.5x on small projects (~10k lines), to 20x on large ones (500k+ lines). Memory usage also drops 12-27%. Codebases that previously hung or were OOM-killed could now complete. Refs #10881 (`#10881 `_) - Skip isort classification in the import checker when no import-ordering message is enabled, and cache the isort configuration so it is built once instead of once per import statement. Skipping the isort processing become a negligible improvement once the caching is applied. pylint became ~17% faster on ansible (~=4500 imports) even with isort enabled. Refs #10886, #2866, #10637 (`#10886 `_)