| 1 |
:Release: 2.0 |
| 2 |
:Date: 2018-07-15 |
| 3 |
|
| 4 |
Summary -- Release highlights |
| 5 |
============================= |
| 6 |
|
| 7 |
* Dropped support for Python 2. This release will work only on Python 3.4+. |
| 8 |
|
| 9 |
If you need to use ``pylint`` with Python 2, you can use Pylint 1.9+. We'll continue |
| 10 |
to do bug releases until 2020, when Python 2 goes officially EOL. |
| 11 |
``pylint`` will gain the ability to analyze Python 2 files, but some checks might not work |
| 12 |
as they will assume that their running environment is Python 2. |
| 13 |
|
| 14 |
* Given the dropping of Python 2, the Python 3 porting mode (enabled via ``--py3k``) can now |
| 15 |
also run with Python 3. |
| 16 |
|
| 17 |
The porting mode used to be a no-op on Python 3, but most of the messages can now be emitted |
| 18 |
when the running interpreter is Python 3. The only messages that won't be emitted are those that |
| 19 |
rely on a particular syntax specific to Python 2, for instance ``print`` as a statement. |
| 20 |
|
| 21 |
|
| 22 |
New checkers |
| 23 |
============ |
| 24 |
* A new check was added, ``useless-object-inheritance``. |
| 25 |
|
| 26 |
This refactoring message is emitted when pylint detects that a class inherits from object, |
| 27 |
which is redundant as in Python 3, every class implicitly inherits from object. |
| 28 |
|
| 29 |
.. code-block:: python |
| 30 |
|
| 31 |
class A(object): |
| 32 |
pass |
| 33 |
|
| 34 |
class A: # better |
| 35 |
pass |
| 36 |
|
| 37 |
* A new check was added, ``comparison-with-callable``. |
| 38 |
|
| 39 |
This refactoring message is emitted when pylint detects that a comparison with a callable was |
| 40 |
made, which might suggest that some parenthesis were omitted, resulting in potential unwanted |
| 41 |
behaviour. |
| 42 |
|
| 43 |
.. code-block:: python |
| 44 |
|
| 45 |
def foo(): |
| 46 |
return None |
| 47 |
|
| 48 |
def goo(): |
| 49 |
return None |
| 50 |
|
| 51 |
if foo == 786: # bad |
| 52 |
pass |
| 53 |
|
| 54 |
if foo() == 786: # good |
| 55 |
pass |
| 56 |
|
| 57 |
* A new check was added, ``chained-comparison``. |
| 58 |
|
| 59 |
This refactoring message is emitted if a boolean operation can be simplified by chaining some |
| 60 |
of its operations. check below example: |
| 61 |
|
| 62 |
.. code-block:: python |
| 63 |
|
| 64 |
if a < b and b < c: |
| 65 |
pass |
| 66 |
|
| 67 |
if a < b < c: # better |
| 68 |
pass |
| 69 |
|
| 70 |
* A new check was added, ``useless-import-alias``. |
| 71 |
|
| 72 |
This refactoring message is emitted when an import alias does not rename the original package. |
| 73 |
|
| 74 |
.. code-block:: python |
| 75 |
|
| 76 |
import numpy as numpy # bad |
| 77 |
import numpy as np # good |
| 78 |
from collection import OrderedDict as OrderedDict # bad |
| 79 |
from collection import OrderedDict as ordered_dict # good |
| 80 |
|
| 81 |
* A new check was added, ``comparison-with-itself``. |
| 82 |
|
| 83 |
This refactoring message is emitted when a variable is compared against itself. |
| 84 |
|
| 85 |
.. code-block:: python |
| 86 |
|
| 87 |
if variable == variable: # bad |
| 88 |
pass |
| 89 |
|
| 90 |
* A new check was added, ``consider-using-in``. |
| 91 |
|
| 92 |
This refactoring message is emitted when a variable is compared against multiple |
| 93 |
values concatenated by ors instead of using the faster, more idiomatic "in" check. |
| 94 |
|
| 95 |
.. code-block:: python |
| 96 |
|
| 97 |
if variable == 1 or variable == 2 or variable == 3: # bad |
| 98 |
pass |
| 99 |
|
| 100 |
if variable in (1, 2, 3): # good |
| 101 |
pass |
| 102 |
|
| 103 |
* A new check was added, ``consider-using-get``. |
| 104 |
|
| 105 |
This refactoring message is emitted when manually checking if a key is in a dictionary |
| 106 |
and getting its value if it is (and optionally a default if not) |
| 107 |
instead of the more idiomatic dict.get. |
| 108 |
|
| 109 |
.. code-block:: python |
| 110 |
|
| 111 |
if 'key' in dictionary: # bad |
| 112 |
variable = dictionary['key'] |
| 113 |
else: |
| 114 |
variable = 'default' |
| 115 |
|
| 116 |
variable = dictionary.get('key', 'default') # good |
| 117 |
|
| 118 |
* A new check was added, ``consider-using-join``. |
| 119 |
|
| 120 |
This refactoring message is emitted when using a for loop over an iterable to join strings |
| 121 |
instead of the faster, less memory consuming and more idiomatic str.join(sequence). |
| 122 |
|
| 123 |
.. code-block:: python |
| 124 |
|
| 125 |
result = '' # bad |
| 126 |
for number in ['1', '2', '3']: |
| 127 |
result += number |
| 128 |
|
| 129 |
result = ''.join(['1', '2', '3']) # good |
| 130 |
|
| 131 |
* New ``useless-return`` message when function or method ends with a "return" or |
| 132 |
"return None" statement and this is the only return statement in the body. |
| 133 |
|
| 134 |
* New ``use-symbolic-message-instead`` message when a message is activated or |
| 135 |
deactivated by id instead of symbol. |
| 136 |
The use of symbol is more explicit and easier to remind. |
| 137 |
|
| 138 |
* A new check was added, ``consider-swap-variables``. |
| 139 |
|
| 140 |
This refactoring message is emitted when using a temporary variable in order |
| 141 |
to swap the values of two variables instead of the shorter, more idiomatic |
| 142 |
approach with tuple-unpacking. |
| 143 |
|
| 144 |
Instead of a temporary variable, the one-line syntax with commas should be used. |
| 145 |
|
| 146 |
See this `style guide`_ document or the Pycon 2007 `swap values presentation` for details. |
| 147 |
|
| 148 |
.. code-block:: python |
| 149 |
|
| 150 |
temp = a # the wrong way |
| 151 |
a = b |
| 152 |
b = temp |
| 153 |
|
| 154 |
a, b = b, a # the right way |
| 155 |
|
| 156 |
* Two new checks, ``invalid-envvar-value`` and ``invalid-envvar-default``, were added. |
| 157 |
|
| 158 |
The former is trigger whenever pylint detects that environment variable manipulation |
| 159 |
functions uses a different type than strings, while the latter is emitted whenever |
| 160 |
the said functions are using a default variable of different type than expected. |
| 161 |
|
| 162 |
* A new check was added, ``subprocess-popen-preexec-fn``, |
| 163 |
|
| 164 |
This refactoring message is emitted when using the keyword argument preexec_fn |
| 165 |
when creating subprocess.Popen instances which may be unsafe when used in |
| 166 |
the presence of threads. |
| 167 |
|
| 168 |
See `subprocess.Popen <https://docs.python.org/3/library/subprocess.html#popen-constructor>`_ |
| 169 |
for full warning details. |
| 170 |
|
| 171 |
* New ``try-except-raise`` message when an except handler block has a bare |
| 172 |
``raise`` statement as its first operator or the exception type being raised |
| 173 |
is the same as the one being handled. |
| 174 |
|
| 175 |
* New ``possibly-unused-variable`` check added. |
| 176 |
|
| 177 |
This is similar to ``unused-variable``, the only difference is that it is |
| 178 |
emitted when we detect a locals() call in the scope of the unused variable. |
| 179 |
The ``locals()`` call could potentially use the said variable, by consuming |
| 180 |
all values that are present up to the point of the call. This new check |
| 181 |
allows to disable this error when the user intentionally uses ``locals()`` |
| 182 |
to consume everything. |
| 183 |
|
| 184 |
For instance, the following code will now trigger this new error: |
| 185 |
|
| 186 |
.. code-block:: python |
| 187 |
|
| 188 |
def func(): |
| 189 |
some_value = some_call() |
| 190 |
return locals() |
| 191 |
|
| 192 |
* New ``unhashable-dict-key`` check added to detect dict lookups using |
| 193 |
unhashable keys such as lists or dicts. |
| 194 |
|
| 195 |
* New ``self-cls-assignment`` warning check added. |
| 196 |
|
| 197 |
This is warning if the first argument of an instance/ class method gets |
| 198 |
assigned |
| 199 |
|
| 200 |
.. code-block:: python |
| 201 |
|
| 202 |
class Foo(object): |
| 203 |
def foo(self, bar): |
| 204 |
self = bar |
| 205 |
|
| 206 |
* New verbose mode option ``--verbose`` to display of extra non-checker-related output. Disabled by default. |
| 207 |
|
| 208 |
* Two new checks were added for recommending dict and set comprehensions where possible. |
| 209 |
|
| 210 |
These two checks are going to flag the following examples: |
| 211 |
|
| 212 |
.. code-block:: python |
| 213 |
|
| 214 |
dict([(k, v) for (k, v) in ...]) # better as {k: v for k, v in ...} |
| 215 |
set([k for k in ...]) # better as {k for k in ...} |
| 216 |
|
| 217 |
Other Changes |
| 218 |
============= |
| 219 |
|
| 220 |
* A couple of performance improvements brought to ``astroid`` should make |
| 221 |
``pylint`` should be a bit faster as well. |
| 222 |
|
| 223 |
We added a new flag, ``max_inferable_values`` on ``astroid.MANAGER`` for |
| 224 |
limiting the maximum amount of values that ``astroid`` can infer when inferring |
| 225 |
values. This change should improve the performance when dealing with large frameworks |
| 226 |
such as ``django``. |
| 227 |
You can also control this behaviour with ``pylint --limit-inference-results`` |
| 228 |
|
| 229 |
We also rewrote how ``nodes_of_class`` and ``get_children`` methods operate which |
| 230 |
should result in a performance boost for a couple of checks. |
| 231 |
|
| 232 |
* Fix a false positive ``inconsistent-return-statements`` message when exception is raised inside |
| 233 |
an else statement. |
| 234 |
|
| 235 |
* Don't warn for ``missing-type-doc`` and/or ``missing-return-type-doc``, if type annotations |
| 236 |
exist on the function signature for a parameter and/or return type. |
| 237 |
|
| 238 |
* Fix a false positive ``inconsistent-return-statements`` message when if |
| 239 |
statement is inside try/except. |
| 240 |
|
| 241 |
* Fix a false positive ``inconsistent-return-statements`` message when |
| 242 |
``while`` loop are used. |
| 243 |
|
| 244 |
* Fix emission of false positive ``no-member`` message for class with |
| 245 |
"private" attributes whose name is mangled. |
| 246 |
|
| 247 |
* Fix ``unused-argument`` false positives with overshadowed variable in dictionary comprehension. |
| 248 |
|
| 249 |
* Fixing false positive ``inconsistent-return-statements`` when |
| 250 |
never returning functions are used (i.e such as sys.exit). |
| 251 |
|
| 252 |
* Fix false positive ``inconsistent-return-statements`` message when a |
| 253 |
function is defined under an if statement. |
| 254 |
|
| 255 |
* Fix false positive ``inconsistent-return-statements`` message by |
| 256 |
avoiding useless exception inference if the exception is not handled. |
| 257 |
|
| 258 |
* Fix false positive ``undefined-variable`` for lambda argument in class definitions |
| 259 |
|
| 260 |
* Suppress false-positive ``not-callable`` messages from certain staticmethod descriptors |
| 261 |
|
| 262 |
* Expand ``ignored-argument-names`` include starred arguments and keyword arguments |
| 263 |
|
| 264 |
* ``singleton-comparison`` will suggest better boolean conditions for negative conditions. |
| 265 |
|
| 266 |
* ``undefined-loop-variable`` takes in consideration non-empty iterred objects before emitting. |
| 267 |
|
| 268 |
For instance, if the loop iterable is not empty, this check will no longer be emitted. |
| 269 |
|
| 270 |
* Enum classes no longer trigger ``too-few-methods`` |
| 271 |
|
| 272 |
* Special methods now count towards ``too-few-methods``, |
| 273 |
and are considered part of the public API. |
| 274 |
They are still not counted towards the number of methods for |
| 275 |
``too-many-methods``. |
| 276 |
|
| 277 |
* ``docparams`` extension allows abstract methods to document returns |
| 278 |
documentation even if the default implementation does not return something. |
| 279 |
They also no longer need to document raising a ``NotImplementedError.`` |
| 280 |
|
| 281 |
* Skip wildcard import check for ``__init__.py``. |
| 282 |
|
| 283 |
* Don't warn :ref:`useless-super-delegation`' if the subclass method has different type annotations. |
| 284 |
|
| 285 |
* Don't warn that a global variable is unused if it is defined by an import |
| 286 |
|
| 287 |
.. code-block:: python |
| 288 |
|
| 289 |
def func(): |
| 290 |
global sys |
| 291 |
import sys |
| 292 |
|
| 293 |
* Added basic support for postponed evaluation of function annotations. |
| 294 |
|
| 295 |
If ``pylint`` detects the corresponding ``from __future__ import annotations`` import, |
| 296 |
it will not emit ``used-before-assignment`` and ``undefined-variable`` in the cases |
| 297 |
triggered by the annotations. |
| 298 |
|
| 299 |
More details on the postponed evaluation of annotations can be read in |
| 300 |
`PEP 563`_. |
| 301 |
|
| 302 |
* A new command line option was added, ``--exit-zero``, for the use of continuous integration |
| 303 |
scripts which abort if a command returns a non-zero status code. If the |
| 304 |
option is specified, and Pylint runs successfully, it will exit with 0 |
| 305 |
regardless of the number of lint issues detected. |
| 306 |
|
| 307 |
Configuration errors, parse errors, and calling Pylint with invalid |
| 308 |
command-line options all still return a non-zero error code, even if |
| 309 |
``--exit-zero`` is specified. |
| 310 |
|
| 311 |
* Don't emit ``unused-import`` anymore for typing imports used in type comments. For instance, |
| 312 |
in the following example pylint used to complain that ``Any`` and ``List`` are not used, |
| 313 |
while they should be considered used by a type checker. |
| 314 |
|
| 315 |
.. code-block:: python |
| 316 |
|
| 317 |
from typing import Any, List |
| 318 |
a = 1 # type: List[Any] |
| 319 |
|
| 320 |
* Fix false positive ``line-too-long`` for commented lines at the end of module |
| 321 |
|
| 322 |
* Fix emitting ``useless-super-delegation`` when changing the default value of keyword arguments. |
| 323 |
|
| 324 |
* Support ``typing.TYPE_CHECKING`` for *:ref:`unused-import`* errors |
| 325 |
|
| 326 |
When modules are imported under ``typing.TYPE_CHECKING`` guard, ``pylint`` |
| 327 |
will no longer emit *:ref:`unused-import`*. |
| 328 |
|
| 329 |
* Fix false positive ``unused-variable`` in lambda default arguments |
| 330 |
|
| 331 |
* ``assignment-from-no-return`` considers methods as well as functions. |
| 332 |
|
| 333 |
If you have a method that doesn't return a value, but later on you assign |
| 334 |
a value to a function call to that method (so basically it will be ``None``), |
| 335 |
then ``pylint`` is going to emit an ``assignment-from-no-return`` error. |
| 336 |
|
| 337 |
* A new flag was added, ``--ignore-none`` which controls the ``no-member`` |
| 338 |
behaviour with respect to ``None`` values. |
| 339 |
|
| 340 |
Previously ``pylint`` was not emitting ``no-member`` if it inferred that |
| 341 |
the owner of an attribute access is a ``None`` value. In some cases, |
| 342 |
this might actually cause bugs, so if you want to check for ``None`` values |
| 343 |
as well, pass ``--ignore-none=n`` to pylint. |
| 344 |
|
| 345 |
* Fix false-positive ``bad-continuation`` for with statements |
| 346 |
|
| 347 |
* Fix false-positive ``bad-whitespace`` message for typing annoatations |
| 348 |
with ellipses in them |
| 349 |
|
| 350 |
* Fix false-positive ``undefined-variable`` for nested lambdas |
| 351 |
|
| 352 |
|
| 353 |
.. _PEP 563: https://peps.python.org/pep-0563/ |
| 354 |
.. _style guide: https://docs.python-guide.org/writing/style/ |