|
12 | 12 | Summary -- Release highlights
|
13 | 13 | =============================
|
14 | 14 |
|
15 |
| -Pylint now supports Python 3.14. |
| 15 | +- Pylint now supports Python 3.14. |
| 16 | + |
| 17 | +- Pylint's inference engine (``astroid``) is now much more precise, |
| 18 | + understanding implicit booleanness and ternary expressions. (Thanks @zenlyj!) |
| 19 | + |
| 20 | +Consider this example: |
| 21 | + |
| 22 | +.. code-block:: python |
| 23 | +
|
| 24 | + class Result: |
| 25 | + errors: dict | None = None |
| 26 | +
|
| 27 | + result = Result() |
| 28 | + if result.errors: |
| 29 | + result.errors[field_key] |
| 30 | + # inference engine understands result.errors cannot be None |
| 31 | + # pylint no longer raises unsubscriptable-object |
16 | 32 |
|
17 | 33 | The required ``astroid`` version is now 4.0.0. See the
|
18 | 34 | `astroid changelog <https://pylint.readthedocs.io/projects/astroid/en/latest/changelog.html#what-s-new-in-astroid-4-0-0>`_
|
19 | 35 | for additional fixes, features, and performance improvements applicable to pylint.
|
20 | 36 |
|
| 37 | +- Handling of ``invalid-name`` at the module level was patchy. Now, |
| 38 | + module-level constants that are reassigned are treated as variables and checked |
| 39 | + against ``--variable-rgx`` rather than ``--const-rgx``. Module-level lists, |
| 40 | + sets, and objects can pass against either regex. |
| 41 | + |
| 42 | +Here, ``LIMIT`` is reassigned, so pylint only uses ``--variable-rgx``: |
| 43 | + |
| 44 | +.. code-block:: python |
| 45 | +
|
| 46 | + LIMIT = 500 # [invalid-name] |
| 47 | + if sometimes: |
| 48 | + LIMIT = 1 # [invalid-name] |
| 49 | +
|
| 50 | +If this is undesired, refactor using *exclusive* assignment so that it is |
| 51 | +evident that this assignment happens only once: |
| 52 | + |
| 53 | +.. code-block:: python |
| 54 | +
|
| 55 | + if sometimes: |
| 56 | + LIMIT = 1 |
| 57 | + else: |
| 58 | + LIMIT = 500 # exclusive assignment: uses const regex, no warning |
| 59 | +
|
| 60 | +Lists, sets, and objects still pass against either ``const-rgx`` or ``variable-rgx`` |
| 61 | +even if reassigned, but are no longer completely skipped: |
| 62 | + |
| 63 | +.. code-block:: python |
| 64 | +
|
| 65 | + MY_LIST = [] |
| 66 | + my_list = [] |
| 67 | + My_List = [] # [invalid-name] |
| 68 | +
|
| 69 | +Remember to adjust the |
| 70 | +`regexes <https://pylint.readthedocs.io/en/latest/user_guide/messages/convention/invalid-name.html>`_ |
| 71 | +and |
| 72 | +`allow lists <https://pylint.readthedocs.io/en/latest/user_guide/configuration/all-options.html#good-names>`_ |
| 73 | +to your liking. |
| 74 | + |
21 | 75 | .. towncrier release notes start
|
0 commit comments