Skip to content

Commit f9a0e27

Browse files
Clarify 4.0 changes
1 parent 9d1c5fe commit f9a0e27

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

doc/whatsnew/4/4.0/index.rst

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,64 @@
1212
Summary -- Release highlights
1313
=============================
1414

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
1632
1733
The required ``astroid`` version is now 4.0.0. See the
1834
`astroid changelog <https://pylint.readthedocs.io/projects/astroid/en/latest/changelog.html#what-s-new-in-astroid-4-0-0>`_
1935
for additional fixes, features, and performance improvements applicable to pylint.
2036

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+
2175
.. towncrier release notes start

0 commit comments

Comments
 (0)