Debian Codegraph @

doc/whatsnew/2/2.4/summary.rst

raw
1 :Release: 2.4
2 :Date: 2019-09-24
3
4
5 Summary -- Release highlights
6 =============================
7
8
9 New checkers
10 ============
11
12 * ``import-outside-toplevel``
13
14 This check warns when modules are imported from places other than a
15 module toplevel, e.g. inside a function or a class.
16
17 * Added a new check, ``consider-using-sys-exit``
18
19 This check is emitted when we detect that a quit() or exit() is invoked
20 instead of sys.exit(), which is the preferred way of exiting in program.
21
22 Closes #2925
23
24 * Added a new check, ``arguments-out-of-order``
25
26 This check warns if you have arguments with names that match those in
27 a function's signature but you are passing them in to the function
28 in a different order.
29
30 Closes #2975
31
32 * Added new checks, ``no-else-break`` and ``no-else-continue``
33
34 These checks highlight unnecessary ``else`` and ``elif`` blocks after
35 ``break`` and ``continue`` statements.
36
37 Closes #2327
38
39 * Added ``unnecessary-comprehension`` that detects unnecessary comprehensions.
40
41 This check is emitted when ``pylint`` finds list-, set- or dict-comprehensions,
42 that are unnecessary and can be rewritten with the list-, set- or dict-constructors.
43
44 Closes #2905
45
46 * Added a new check, ``invalid-overridden-method``
47
48 This check is emitted when we detect that a method is overridden
49 as a property or a property is overridden as a method. This can indicate
50 a bug in the application code that will trigger a runtime error.
51
52 Closes #2670
53
54 * Added a new check, ``redeclared-assigned-name``
55
56 This check is emitted when ``pylint`` detects that a name was assigned one or multiple times in the same assignment,
57 which indicate a potential bug.
58
59 Closes #2898
60
61 * Added a new check, ``self-assigning-variable``
62
63 This check is emitted when we detect that a variable is assigned
64 to itself, which might indicate a potential bug in the code application.
65
66 For example, the following would raise this warning::
67
68 def new_a(attr, attr2):
69 a_inst = Aclass()
70 a_inst.attr2 = attr2
71 # should be: a_inst.attr = attr, but have a typo
72 attr = attr
73 return a_inst
74
75 Closes #2930
76
77 * Added a new check ``property-with-parameters`` which detects when a property
78 has more than a single argument.
79
80 Closes #3006
81
82 * Added ``subprocess-run-check`` to handle subprocess.run without explicitly set ``check`` keyword.
83
84 Closes #2848
85
86 * We added a new check message ``dict-iter-missing-items``.
87 This is emitted when trying to iterate through a dict in a for loop without calling its .items() method.
88
89 Closes #2761
90
91 * We added a new check message ``missing-parentheses-for-call-in-test``.
92 This is emitted in case a call to a function is made inside a test but
93 it misses parentheses.
94
95 * A new check ``class-variable-slots-conflict`` was added.
96
97 This check is emitted when ``pylint`` finds a class variable that conflicts with a slot
98 name, which would raise a ``ValueError`` at runtime.
99
100 For example, the following would raise an error::
101
102 class A:
103 __slots__ = ('first', 'second')
104 first = 1
105
106 * A new check ``preferred-module`` was added.
107
108 This check is emitted when ``pylint`` finds an imported module that has a
109 preferred replacement listed in ``preferred-modules``.
110
111 For example, you can set the preferred modules as ``xml:defusedxml,json:ujson``
112 to make ``pylint`` suggest using ``defusedxml`` instead of ``xml``
113 and ``ujson`` rather than ``json``.
114
115 * A new extension ``broad_try_clause`` was added.
116
117 This extension enforces a configurable maximum number of statements inside
118 of a try clause. This facilitates enforcing PEP 8's guidelines about try / except
119 statements and the amount of code in the try clause.
120
121 You can enable this extension using ``--load-plugins=pylint.extensions.broad_try_clause``
122 and you can configure the amount of statements in a try statement using
123 ``--max-try-statements``.
124
125
126 Other Changes
127 =============
128
129 * Don't emit ``protected-access`` when a single underscore prefixed attribute is used
130 inside a special method
131
132 Closes #1802
133
134 * ``len-as-condition`` now only fires when a ``len(x)`` call is made without an explicit comparison.
135
136 The message and description accompanying this checker has been changed
137 reflect this new behavior, by explicitly asking to either rely on the
138 fact that empty sequence are false or to compare the length with a scalar.
139
140 OK::
141
142 if len(x) == 0:
143 pass
144
145 while not len(x) == 0:
146 pass
147
148 assert len(x) > 5, message
149
150 KO::
151
152 if not len(x):
153 pass
154
155 while len(x) and other_cond:
156 pass
157
158 assert len(x), message
159
160 * A file is now read from stdin if the ``--from-stdin`` flag is used on the
161 command line. In addition to the ``--from-stdin`` flag a (single) file
162 name needs to be specified on the command line, which is needed for the
163 report.
164
165 * The checker for ungrouped imports is now more permissive.
166
167 The import can now be sorted alphabetically by import style.
168 This makes pylint compatible with isort.
169
170 The following imports do not trigger an ``ungrouped-imports`` anymore ::
171
172 import unittest
173 import zipfile
174 from unittest import TestCase
175 from unittest.mock import MagicMock
176
177 * The checker for missing return documentation is now more flexible.
178
179 The following does not trigger a ``missing-return-doc`` anymore ::
180
181 def my_func(self):
182 """This is a docstring.
183
184 Returns
185 -------
186 :obj:`list` of :obj:`str`
187 List of strings
188 """
189 return ["hi", "bye"] #@
190
191 * ``signature-mutators`` CLI and config option was added.
192
193 With this option, users can choose to ignore ``too-many-function-args``, ``unexpected-keyword-arg``,
194 and ``no-value-for-parameter`` for functions decorated with decorators that change
195 the signature of a decorated function.
196
197 For example a test may want to make use of hypothesis.
198 Adding ``hypothesis.extra.numpy.arrays`` to ``signature_mutators``
199 would mean that ``no-value-for-parameter`` would not be raised for::
200
201 @given(img=arrays(dtype=np.float32, shape=(3, 3, 3, 3)))
202 def test_image(img):
203 ...
204
205 * Allow the option of f-strings as a valid logging string formatting method.
206
207 ``logging-fstring--interpolation`` has been merged into
208 ``logging-format-interpolation`` to allow the ``logging-format-style`` option
209 to control which logging string format style is valid.
210 To allow this, a new ``fstr`` value is valid for the ``logging-format-style``
211 option.
212
213 * ``--list-msgs-enabled`` command was added.
214
215 When enabling/disabling several messages and groups in a config file,
216 it can be unclear which messages are actually enabled and which are disabled.
217 This new command produces the final resolved lists of enabled/disabled messages,
218 sorted by symbol but with the ID provided for use with ``--help-msg``.