What's New In Pylint 1.6¶
- Release
1.6.0
- Date
2016-07-07
Summary -- Release highlights¶
Nothing major.
New checkers¶
We added a new recommendation check,
consider-iterating-dictionary, which is emitted when a dictionary is iterated by using.keys().For instance, the following code would trigger this warning, since the dictionary's keys can be iterated without calling the method explicitly.
for key in dictionary.keys(): ... # Can be refactored to: for key in dictionary: ...
trailing-newlinescheck was added, which is emitted when a file has trailing newlines.invalid-length-returnedcheck was added, which is emitted when the__len__special method returns something else than a non-negative number. For instance, this example is triggering it:class Container(object): def __len__(self): return self._items # Oups, forgot to call len() over it.
Add a new check to the check_docs extension for looking for duplicate constructor parameters in a class constructor docstring or in a class docstring.
The check
multiple-constructor-docis emitted when the parameter is documented in both places.We added a new extension plugin,
pylint.extensions.mccabe, which can be used for warning about the complexity in the code.You can enable it as in:
$ pylint module_or_project --load-plugins=pylint.extensions.mccabe
See more at Design checker
New features¶
generated-membersnow supports qualified names through regular expressions.For instance, for ignoring all the errors generated by
numpy.core's attributes, we can now use:$ pylint a.py --generated-members=numpy.*
Add the ability to ignore files based on regex matching, with the new
--ignore-patternsoption.Rather than clobber the existing
ignoreoption, we decided to have a separate option for it. For instance, for ignoring all the test files, we can now use:$ pylint myproject --ignore-patterns=test.*?py
We added a new option,
redefining-builtins-modules, which is used for defining the modules which can redefine builtins. pylint will emit an error when a builtin is redefined, such as defining a variable callednext. But in some cases, the builtins can be redefined in the case they are imported from other places, different than thebuiltinsmodule, such is the case forsix.moves, which contains more forward-looking functions:$ cat a.py # Oups, now pylint emits a redefined-builtin message. from six.moves import open $ pylint a.py --redefining-builtins-modules=six.moves
Default values:
six.moves,future.builtins
Bug fixes¶
Fixed a bug where the top name of a qualified import was detected as an unused variable.
We don't warn about
invalid-sequence-indexif the indexed object has unknown base classes, that Pylint cannot deduce.
Other Changes¶
The
bad-builtincheck was moved into an extension.The check was complaining about used builtin functions which were supposed to not be used. For instance,
mapandfilterwere falling into this category, since better alternatives can be used, such as list comprehensions. But the check was annoying, since usingmaporfiltercan have its use cases and as such, we decided to move it to an extension check instead. It can now be enabled through--load-plugins=pylint.extensions.bad_builtin.We use the
configparserbackport internally, for Python 2.This allows having comments inside list values, in the configuration, such as:
disable=no-member, # Don't like this check bad-indentation
We now use the isort package internally.
This improves the
`wrong-import-ordercheck, so now we should have less false positives regarding the import order.We do not emit
import-errororno-name-in-modulefor fallback import blocks by default.A fallback import block can be considered a TryExcept block, which contains imports in both branches, such as:
try: import urllib.request as request except ImportError: import urllib2 as request
In the case where pylint can not find one import from the
exceptbranch, then it will emit animport-error, but this gets cumbersome when trying to write compatible code for both Python versions. As such, we don't check these blocks by default, but the analysis can be enforced by using the new--analyse-fallback-blockflag.reimportedis emitted when the same name is imported from different module, as in:from collections import deque, OrderedDict, deque
Deprecated features¶
The HTML support was deprecated and will be eventually removed in Pylint 1.7.0.
This feature was lately a second class citizen in Pylint, being often neglected and having a couple of bugs. Since we now have the JSON reporter, this can be used as a basis for more prettier HTML outputs than what Pylint can currently offer.
The
--files-outputoption was deprecated and will be eventually removed in Pylint 1.7.0.The
--optimize-astoption was deprecated and will be eventually removed in Pylint 1.7.0.The option was initially added for handling pathological cases, such as joining too many strings using the addition operator, which was leading pylint to have a recursion error when trying to figure out what the string was. Unfortunately, we decided to ignore the issue, since the pathological case would have happen when the code was parsed by Python as well, without actually reaching the runtime step and as such, we will remove the option in the future.
The
check_docsextension is now deprecated. The extension is still available under thedocparamsname, so this should work:$ pylint module_or_package --load-extensions=pylint.extensions.docparams
The old name is still kept for backward compatibility, but it will be eventually removed.
Removed features¶
None yet
