summaryrefslogtreecommitdiff
path: root/doc/whatsnew/2.4.rst
blob: fa9cc5d3b41280429faae1c368cfe84cd1548fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
**************************
 What's New in Pylint 2.4
**************************

:Release: 2.4
:Date: TBA


Summary -- Release highlights
=============================


New checkers
============

* Added `subprocess-run-check` to handle subprocess.run without explicitly set `check` keyword.

  Close #2848

* We added a new check message ``dict-iter-missing-items``.
  This is emitted when trying to iterate through a dict in a for loop without calling its .items() method.

  Closes #2761

* We added a new check message ``missing-parentheses-for-call-in-test``.
  This is emitted in case a call to a function is made inside a test but
  it misses parentheses.

* A new check ``class-variable-slots-conflict`` was added.

  This check is emitted when ``pylint`` finds a class variable that conflicts with a slot
  name, which would raise a ``ValueError`` at runtime.

  For example, the following would raise an error::

    class A:
        __slots__ = ('first', 'second')
        first = 1

* A new check ``preferred-module`` was added.

  This check is emitted when ``pylint`` finds an imported module that has a
  preferred replacement listed in ``preferred-modules``.

  For example, you can set the preferred modules as ``xml:defusedxml,json:ujson``
  to make ``pylint`` suggest using ``defusedxml`` instead of ``xml``
  and ``ujson`` rather than ``json``.

* A new extension ``broad_try_clause`` was added.

  This extension enforces a configurable maximum number of statements inside
  of a try clause. This facilitates enforcing PEP 8's guidelines about try / except
  statements and the amount of code in the try clause.

  You can enable this extension using ``--load-plugins=pylint.extensions.broad_try_clause``
  and you can configure the amount of statements in a try statement using
  ``--max-try-statements``.


Other Changes
=============

* ``len-as-condition`` now only fires when a ``len(x)`` call is made without an explicit comparison.

  The message and description accompanying this checker has been changed
  reflect this new behavior, by explicitly asking to either rely on the
  fact that empty sequence are false or to compare the length with a scalar.

  OK::

    if len(x) == 0:
      pass

    while not len(x) == 0:
      pass

    assert len(x) > 5, message

  KO::

    if not len(x):
      pass

    while len(x) and other_cond:
      pass

    assert len(x), message

* A file is now read from stdin if the ``--from-stdin`` flag is used on the
  command line. In addition to the ``--from-stdin`` flag a (single) file
  name needs to be specified on the command line, which is needed for the
  report.

* The checker for ungrouped imports is now more permissive.

The import can now be sorted alphabetically by import style.
This makes pylint compatible with isort.

The following imports do not trigger an ``ungrouped-imports`` anymore ::

    import unittest
    import zipfile
    from unittest import TestCase
    from unittest.mock import MagicMock

* The checker for missing return documentation is now more flexible.

The following does not trigger a ``missing-return-doc`` anymore ::

    def my_func(self):
        """This is a docstring.

        Returns
        -------
        :obj:`list` of :obj:`str`
            List of strings
        """
        return ["hi", "bye"] #@

* Can choose to ignore `too-many-function-args`, `unexpected-keyword-arg`,
  and `no-value-for-parameter` for functions decorated with certain decorators.

For example a test may want to make use of hypothesis.
Adding `hypothesis.extra.numpy.arrays` to `function_mutators`
would mean that `no-value-for-parameter` would not be raised for::

    @given(img=arrays(dtype=np.float32, shape=(3, 3, 3, 3)))
    def test_image(img):
        ...