Debian Codegraph @

doc/whatsnew/2/2.13/summary.rst

raw
1 :Release: 2.13
2 :Date: 2022-03-24
3
4 Summary -- Release highlights
5 =============================
6
7 In 2.13, we introduced a new check to deal with unicode security issues. On top of that a lot of work was
8 done inside the unicode checker by @CarliJoy. We also introduced a new check when importing private name
9 and for unnecessary ellipsis among other.
10
11 We fixed long standing issues related to duplicate code that could not be disabled, line numbers
12 that were not accurate some of the time, and added the ability to lint all files in a directory without
13 specifying each one. One of the most anticipated issue from the repository. Thank you @matusvalo !
14
15 A lot of ``undefined-variables`` and ``used-before-assignment`` issues were resolved thanks to @jacobtylerwalls.
16
17 We started integrating ``pylint-error`` the documentation created by @vald-phoenix a developer from Hlyniane,
18 Ukraine. We hope he's doing well despite the current situation. The deployment is set up but `there's still a lot to do so we welcome any community effort
19 help to review, integrate, and add good/bad examples <https://github.com/pylint-dev/pylint/issues/5953>`_. This should be doable
20 without any pylint or astroid knowledge, so this is the perfect entrypoint if you want to contribute
21 to pylint without investing any time learning the internals.
22
23 This release is the last one to support interpreter below 3.7.2, 3.6 end of life was reached in december 2021.
24
25 New checkers
26 ============
27
28 * Added several checkers to deal with unicode security issues
29 (see `Trojan Sources <https://trojansource.codes/>`_ and
30 `PEP 672 <https://peps.python.org/pep-0672/>`_ for details) that also
31 concern the readability of the code. In detail the following checks were added:
32
33 * ``bad-file-encoding`` checks that the file is encoded in UTF-8 as suggested by
34 `PEP8 <https://peps.python.org/pep-0008/#source-file-encoding>`_.
35 UTF-16 and UTF-32 are `not supported by Python <https://bugs.python.org/issue1503789>`_
36 at the moment. If this ever changes
37 ``invalid-unicode-codec`` checks that they aren't used, to allow for backwards
38 compatibility.
39
40 * ``bidirectional-unicode`` checks for bidirectional unicode characters that
41 could make code execution different than what the user expects.
42
43 * ``invalid-character-backspace``, ``invalid-character-carriage-return``,
44 ``invalid-character-sub``, ``invalid-character-esc``,
45 ``invalid-character-zero-width-space`` and ``invalid-character-nul``
46 to check for possibly harmful unescaped characters.
47
48 Closes #5281
49
50 * ``unnecessary-ellipsis``: Emitted when the ellipsis constant is used unnecessarily.
51
52 Closes #5460
53
54 * Added new checker ``typevar-name-missing-variance``. Emitted when a covariant
55 or contravariant ``TypeVar`` does not end with ``_co`` or ``_contra`` respectively or
56 when a ``TypeVar`` is not either but has a suffix.
57
58 * Add ``modified-iterating-list``, ``modified-iterating-dict``, and ``modified-iterating-set``,
59 emitted when items are added to or removed from respectively a list, dictionary or
60 set being iterated through.
61
62 Closes #5348
63
64 * Add checker ``redefined-slots-in-subclass``: Emitted when a slot is redefined in a subclass.
65
66 Closes #5617
67
68 * Rewrote Checker of ``non-ascii-name``.
69 It now ensures __all__ Python names are ASCII and also properly
70 checks the names of imports (``non-ascii-module-import``) as
71 well as file names (``non-ascii-file-name``) and emits their respective new warnings.
72
73 Non ASCII characters could be homoglyphs (look alike characters) and hard to
74 enter on a non specialized keyboard.
75 See `Confusable Characters in PEP 672`_
76
77 .. _`Confusable Characters in PEP 672`: https://peps.python.org/pep-0672/#confusable-characters-in-identifiers
78
79 * Added ``cache-max-size-none`` checker with checks for the use of ``functools.lru_cache``
80 on class methods with a ``maxsize`` of ``None``. This is unrecommended as it
81 creates memory leaks by never letting the instance get garbage collected.
82
83 Closes #5670
84 Closes #6180
85
86 Removed checkers
87 ================
88
89 * Removed the deprecated ``check_docs`` extension. You can use the ``docparams`` checker
90 to get the checks previously included in ``check_docs``.
91
92 Closes #5322
93
94 Extensions
95 ==========
96 * New extension ``import-private-name``: indicate imports of external private packages
97 and objects (prefixed with ``_``). It can be loaded using ``load-plugins=pylint.extensions.private_import``.
98
99 Closes #5463
100
101 * Pyreverse - add output in mermaid-js format and html which is an mermaid js diagram with html boilerplate
102
103 * ``TypingChecker``
104
105 * Added new check ``broken-noreturn`` to detect broken uses of ``typing.NoReturn``
106 if ``py-version`` is set to Python ``3.7.1`` or below.
107 https://bugs.python.org/issue34921
108
109 * Added new check ``broken-collections-callable`` to detect broken uses of ``collections.abc.Callable``
110 if ``py-version`` is set to Python ``3.9.1`` or below.
111 https://bugs.python.org/issue42965
112
113 * ``DocstringParameterChecker``
114
115 * Fixed incorrect classification of Numpy-style docstring as Google-style docstring for
116 docstrings with property setter documentation.
117 Docstring classification is now based on the highest amount of matched sections instead
118 of the order in which the docstring styles were tried.
119
120 * ``DocStringStyleChecker``
121
122 * Disable checker ``bad-docstring-quotes`` for Python <= 3.7, because in these versions the line
123 numbers for decorated functions and classes are not reliable which interferes with the checker.
124
125 Closes #3077
126
127 Other Changes
128 =============
129
130 * Include ``testing_pylintrc`` in source and wheel distributions.
131
132 Closes #6028
133
134 * Fix false positive for ``unused-import`` when disabling both ``used-before-assignment`` and ``undefined-variable``.
135
136 Closes #6089
137
138 * Fix false positive for ``unnecessary-ellipsis`` when using an ellipsis as a default argument.
139
140 Closes #5973
141
142 * Add missing dunder methods to ``unexpected-special-method-signature`` check.
143
144 * No longer emit ``no-member`` in for loops that reference ``self`` if the binary operation that
145 started the for loop uses a ``self`` that is encapsulated in tuples or lists.
146
147 Refs pylint-dev/astroid#1360
148 Closes #4826
149
150 * Fix matching ``--notes`` options that end in a non-word character.
151
152 Closes #5840
153
154 * The line numbering for messages related to function arguments is now more accurate. This can
155 require some message disables to be relocated to updated positions.
156
157 * ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids
158 were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disables using these msgids will break.
159 This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and
160 ``basestring-builtin`` from the now deleted python 3K+ checker. There is now a check that we're not using
161 existing msgids or symbols from deleted checkers.
162
163 Closes #5729
164
165 * Add ``--recursive`` option to allow recursive discovery of all modules and packages in subtree. Running pylint with
166 ``--recursive=y`` option will check all discovered ``.py`` files and packages found inside subtree of directory provided
167 as parameter to pylint.
168
169 Closes #352
170
171 * Updated the position of messages for class and function definitions to no longer cover
172 the complete definition. Only the ``def`` or ``class`` + the name of the class/function
173 are covered.
174
175 Closes #5466
176
177 * Reinstated checks from the python3 checker that are still useful for python 3
178 (``eq-without-hash``). This is now in the ``pylint.extensions.eq_without_hash`` optional
179 extension.
180
181 Closes #5025
182
183 * Fix false-negative for ``assignment-from-none`` checker with list.sort() method.
184
185 Closes #5722
186
187 * Fix ``unused-private-member`` false positive when accessing private methods through ``property``.
188
189 Closes #4756
190
191 * Fixed crash from ``arguments-differ`` and ``arguments-renamed`` when methods were
192 defined outside the top level of a class.
193
194 Closes #5648
195
196 * Better warning messages for useless else or elif when a function returns early.
197
198 Closes #5614
199
200 * Asterisks are no longer required in Sphinx and Google style parameter documentation
201 for ``missing-param-doc`` and are parsed correctly.
202
203 Closes #5815
204 Closes #5406
205
206 * Fixed an ``AstroidError`` in 2.13.0 raised by the ```duplicate-code``` checker with
207 ``ignore-imports`` or ``ignore-signatures`` enabled.
208
209 Closes #6301
210
211 * Use the ``tomli`` package instead of ``toml`` to parse ``.toml`` files.
212
213 Closes #5885
214
215 * Fixed false positive ``consider-using-dict-comprehension`` when creating a dict
216 using a list of tuples where key AND value vary depending on the same condition.
217
218 Closes #5588
219
220 * When run in parallel mode ``pylint`` now pickles the data passed to subprocesses with
221 the ``dill`` package. The ``dill`` package has therefore been added as a dependency.
222
223 * Fixed false positive for ``global-variable-undefined`` when ``global`` is used with a class name
224
225 Closes #3088
226
227 * Fixed crash on properties and inherited class methods when comparing them for
228 equality against an empty dict.
229
230 Closes #5646
231
232 * By default, pylint does no longer take files starting with ``.#`` into account. Those are
233 considered `Emacs file locks`_. This behavior can be reverted by redefining the
234 ``ignore-patterns`` option.
235
236 Closes #367
237
238 .. _`Emacs file locks`: https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html
239
240 * Fix ``super-init-not-called`` when parent or ``self`` is a ``Protocol``
241
242 Closes #4790
243
244 * The issue template for crashes is now created for crashes which were previously not covered
245 by this mechanism.
246
247 Closes #5668
248
249 * An astroid issue where symlinks were not being taken into account
250 was fixed
251
252 Closes #1470
253 Closes #3499
254 Closes #4302
255 Closes #4798
256 Closes #5081
257
258 * Fix false negative for ``undefined-variable`` and related variable messages
259 when the same undefined variable is used as a type annotation and is
260 accessed multiple times, or is used as a default argument to a function.
261
262 Closes #5399
263
264 * Emit ``used-before-assignment`` instead of ``undefined-variable`` when attempting
265 to access unused type annotations.
266
267 Closes #5713
268
269 * Fixed an issue where ``ungrouped-imports`` could not be disabled without raising
270 ``useless-suppression``.
271
272 Refs #2366
273
274 * Fixed a crash on ``__init__`` nodes when the attribute was previously uninferable due to a cache
275 limit size. This limit can be hit when the inheritance pattern of a class (and therefore of the ``__init__`` attribute) is very large.
276
277 Closes #5679
278
279 * Fixed extremely long processing of long lines with comma's.
280
281 Closes #5483
282
283 * Fix false positive ``super-init-not-called`` for classes that inherit their ``init`` from
284 a parent.
285
286 Closes #4941
287
288 * Fix false positives for ``used-before-assignment`` from using named
289 expressions in a ternary operator test and using that expression as
290 a call argument.
291
292 Closes #5177, #5212
293
294 * Fixed crash with recursion error for inference of class attributes that referenced
295 the class itself.
296
297 Closes #5408
298 Refs pylint-dev/astroid#1392
299
300 * Fixed false positive for ``unused-argument`` when a method overridden in a subclass
301 does nothing with the value of a keyword-only argument.
302
303 Closes #5771
304 Refs pylint-dev/astroid#1382
305
306 * Optimize parsing of long lines when ``missing-final-newline`` is enabled.
307
308 Closes #5724
309
310 * Fix false positive for ``used-before-assignment`` from a class definition
311 nested under a function subclassing a class defined outside the function.
312
313 Closes #4590
314
315 * Fix ``unnecessary_dict_index_lookup`` false positive when deleting a dictionary's entry.
316
317 Closes #4716
318
319 * Fix false positive for ``used-before-assignment`` when an except handler
320 shares a name with a test in a filtered comprehension.
321
322 Closes #5817
323
324 * Fix a crash in ``unused-private-member`` checker when analyzing code using
325 ``type(self)`` in bound methods.
326
327 Closes #5569
328
329 * Fix crash in ``unnecessary-dict-index-lookup`` checker if the output of
330 ``items()`` is assigned to a 1-tuple.
331
332 Closes #5504
333
334 * Fixed crash with slots assignments and annotated assignments.
335
336 Closes #5479
337
338 * Fixed a crash in ``unspecified-encoding`` checker when providing ``None``
339 to the ``mode`` argument of an ``open()`` call.
340
341 Closes #5731
342
343 * Fixed a crash involving a ``NewType`` named with an f-string.
344
345 Closes #5770
346 Refs pylint-dev/astroid#1400
347
348 * Improved ``bad-open-mode`` message when providing ``None`` to the ``mode``
349 argument of an ``open()`` call.
350
351 Closes #5733
352
353 * Fix false negative for ``consider-iterating-dictionary`` during membership checks encapsulated in iterables
354 or ``not in`` checks
355
356 Closes #5323
357
358 * Allow disabling ``duplicate-code`` with a disable comment when running through
359 pylint.
360
361 Closes #214
362
363 * Fix false positive for ``undefined-variable`` when ``namedtuple`` class
364 attributes are used as return annotations.
365
366 Closes #5568
367
368 * Added confidence level ``CONTROL_FLOW`` for warnings relying on assumptions
369 about control flow.
370
371 * ``used-before-assignment`` now considers that assignments in a try block
372 may not have occurred when the except or finally blocks are executed.
373
374 Closes #85, #2615
375
376 * Fixed false negative for ``used-before-assignment`` when a conditional
377 or context manager intervened before the try statement that suggested
378 it might fail.
379
380 Closes #4045
381
382 * Fixed false negative for ``used-before-assignment`` in finally blocks
383 if an except handler did not define the assignment that might have failed
384 in the try block.
385
386 * Fix a false positive for ``assigning-non-slot`` when the slotted class
387 defined ``__setattr__``.
388
389 Closes #3793
390
391 * Fixed a false positive for ``invalid-class-object`` when the object
392 being assigned to the ``__class__`` attribute is uninferable.
393
394 * Added a ``testutil`` extra require to the packaging, as ``gitpython`` should not be a dependency
395 all the time but is still required to use the primer helper code in ``pylint.testutil``. You can
396 install it with ``pip install pylint[testutil]``.
397
398 Closes #5486
399
400 * Fixed a false positive for ``used-before-assignment`` when a named expression
401 appears as the first value in a container.
402
403 Closes #5112
404
405 * Fixed false positive for ``used-before-assignment`` with self-referential type
406 annotation in conditional statements within class methods.
407
408 Closes #5499
409
410 * ``used-before-assignment`` now assumes that assignments in except blocks
411 may not have occurred and warns accordingly.
412
413 Closes #4761
414
415 * When evaluating statements after an except block, ``used-before-assignment``
416 assumes that assignments in the except blocks took place if the
417 corresponding try block contained a return statement.
418
419 Closes #5500
420
421 * Fixed a false negative for ``used-before-assignment`` when some but not all
422 except handlers defined a name relied upon after an except block when the
423 corresponding try block contained a return statement.
424
425 Closes #5524
426
427 * When evaluating statements in the ``else`` clause of a loop, ``used-before-assignment``
428 assumes that assignments in the except blocks took place if the
429 except handlers constituted the only ways for the loop to finish without
430 breaking early.
431
432 Closes #5683
433
434 * ``used-before-assignment`` now checks names in try blocks.
435
436 * Fixed false positive with ``used-before-assignment`` for assignment expressions
437 in lambda statements.
438
439 Closes #5360, #3877
440
441 * Improve ``invalid-name`` check for ``TypeVar`` names.
442 The accepted pattern can be customized with ``--typevar-rgx``.
443
444 Closes #3401
445
446 * Fixed a false positive (affecting unreleased development) for
447 ``used-before-assignment`` involving homonyms between filtered comprehensions
448 and assignments in except blocks.
449
450 Closes #5586
451
452 * Fixed crash on list comprehensions that used ``type`` as inner variable name.
453
454 Closes #5461
455
456 * Fixed crash in ``use-maxsplit-arg`` checker when providing the ``sep`` argument
457 to ``str.split()`` by keyword.
458
459 Closes #5737
460
461 * Fix false positive for ``unused-variable`` for a comprehension variable matching
462 an outer scope type annotation.
463
464 Closes #5326
465
466 * Fix false negative for ``undefined-variable`` for a variable used multiple times
467 in a comprehension matching an unused outer scope type annotation.
468
469 Closes #5654
470
471 * Require Python ``3.6.2`` to run pylint.
472
473 Closes #5065
474
475 * Fixed crash on uninferable decorators on Python 3.6 and 3.7
476
477 * Emit ``redefined-outer-name`` when a nested except handler shadows an outer one.
478
479 Closes #4434
480 Closes #5370
481
482 * ``encoding`` can now be supplied as a positional argument to calls that open
483 files without triggering ``unspecified-encoding``.
484
485 Closes #5638
486
487 * Fatal errors now emit a score of 0.0 regardless of whether the linted module
488 contained any statements
489
490 Closes #5451
491
492 * ``fatal`` was added to the variables permitted in score evaluation expressions.
493
494 * The default score evaluation now uses a floor of 0.
495
496 Closes #2399
497
498 * Fix ``comparison-with-callable`` false positive for callables that raise, such
499 as typing constants.
500
501 Closes #5557
502
503 * When invoking ``pylint``, ``epylint``, ``symilar`` or ``pyreverse`` by importing them in a python file
504 you can now pass an ``argv`` keyword besides patching ``sys.argv``.
505
506 Closes #5320
507
508 * The ``PyLinter`` class will now be initialized with a ``TextReporter``
509 as its reporter if none is provided.
510
511 * Fix false positive ``not-callable`` with attributes that alias ``NamedTuple``
512
513 Fixes part of #1730
514
515 * The ``testutils`` for unittests now accept ``end_lineno`` and ``end_column``. Tests
516 without these will trigger a ``DeprecationWarning``.
517
518 * ``arguments-differ`` will no longer complain about method redefinitions with extra parameters
519 that have default values.
520
521 Closes #1556, #5338
522
523 * Disables for ``deprecated-module`` and similar warnings for stdlib features deprecated
524 in newer versions of Python no longer raise ``useless-suppression`` when linting with
525 older Python interpreters where those features are not yet deprecated.
526
527 * Importing the deprecated stdlib module ``xml.etree.cElementTree`` now emits ``deprecated_module``.
528
529 Closes #5862
530
531 * Importing the deprecated stdlib module ``distutils`` now emits ``deprecated_module`` on Python 3.10+.
532
533 * Fixed false positive ``unexpected-keyword-arg`` for decorators.
534
535 Closes #258
536
537 * ``missing-raises-doc`` will now check the class hierarchy of the raised exceptions
538
539 .. code-block:: python
540
541 def my_function():
542 """My function.
543
544 Raises:
545 Exception: if something fails
546 """
547 raise ValueError
548
549 Closes #4955
550
551 * Fixed false positive for ``unused-variable`` when a ``nonlocal`` name is assigned as part of a multi-name assignment.
552
553 Closes #3781
554
555 * Fix false positive - Allow unpacking of ``self`` in a subclass of ``typing.NamedTuple``.
556
557 Closes #5312
558
559 * Fixed false negative ``unpacking-non-sequence`` when value is an empty list.
560
561 Closes #5707
562
563 * Fixed false positive for ``global-variable-not-assigned`` when the ``del`` statement is used
564
565 Closes #5333
566
567 * Fix type hints in class diagrams generated by pyreverse for class methods and methods returning None.
568
569 * Output better error message if unsupported file formats are used with ``pyreverse``.
570
571 Closes #5950
572
573 * Fixed false positive for ``unused-argument`` when a ``nonlocal`` name is used
574 in a nested function that is returned without being called by its parent.
575
576 Closes #5187
577
578 * Avoid emitting ``raising-bad-type`` when there is inference ambiguity on
579 the variable being raised.
580
581 Closes #2793
582
583 * Fix false positive for ``superfluous-parens`` for patterns like
584 "return (a or b) in iterable".
585
586 Closes #5803
587
588 * Fix a crash in the ``unsupported-membership-test`` checker when assigning
589 multiple constants to class attributes including ``__iter__`` via unpacking.
590
591 Closes #6366
592
593 * Fix false positive for ``used-before-assignment`` for assignments taking place via
594 nonlocal declarations after an earlier type annotation.
595
596 Closes #5394
597
598 * Fixed a false positive for ``unused-variable`` when a builtin specified in
599 ``--additional-builtins`` is given a type annotation.
600
601 Closes #6388
602
603 * Fix false positive for :ref:`nonexistent-operator`' when repeated '-' are
604 separated (e.g. by parens).
605
606 Closes #5769
607
608 * Fix a false positive for ``undefined-loop-variable`` when the ``else`` of a ``for``
609 loop raises or returns.
610
611 Closes #5971
612
613 * Only raise ``not-callable`` when all the inferred values of a property are not callable.
614
615 Closes #5931
616
617 * Fix false positive for ``unused-variable`` for classes inside functions
618 and where a metaclass is provided via a call.
619
620 Closes #4020
621
622 * Avoid reporting ``superfluous-parens`` on expressions using the ``is not`` operator.
623
624 Closes #5930
625
626 * Fix a false positive for ``undefined-loop-variable`` for a variable used in a lambda
627 inside the first of multiple loops.
628
629 Closes #6419
630
631 * Fix false positive for ``unsubscriptable-object`` in Python 3.8 and below for
632 statements guarded by ``if TYPE_CHECKING``.
633
634 Closes #3979
635
636 * Fix a crash when accessing ``__code__`` and assigning it to a variable.
637
638 Closes #6539
639
640 * Fix a crash when linting a file that passes an integer ``mode=`` to
641 ``open``
642
643 Closes #6414
644
645 * Fix false positives for ``no-name-in-module`` and ``import-error`` for ``numpy.distutils``
646 and ``pydantic``.
647
648 Closes #6497
649
650 * Fix ``IndexError`` crash in ``uninferable_final_decorators`` method.
651
652 Refs #6531
653
654 * Fix a crash in ``unnecessary-dict-index-lookup`` when subscripting an attribute.
655
656 Closes #6557
657
658 * Fix a false positive for ``undefined-loop-variable`` when using ``enumerate()``.
659
660 Closes #6593