-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Enhancement ✨Improvement to a componentImprovement to a componentGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributors
Description
Steps to reproduce
if len([]) == 0:
passpylint will lint this as len-as-condition. This seems to go back to PEP stating:
- For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
Yes:
if not seq:` if seq:No:
if len(seq): if not len(seq):
While I do agree that if len(seq) is not ideal, I don't think the same applies to if len(seq) == 0. I personally prefer the explicitness of the comparison and the applicability to everything that supports len. There is also the point of consistency in comarisons like:
if len(seq) == 0:
pass
elif len(seq) == 1:
passCurrent behavior
if len([]) and if len([]) == 0 are both linted.
Expected behavior
Only if len([]) is linted.
pylint --version output
pylint 2.2.2
astroid 2.1.0
Python 3.7.2 (default, Dec 24 2018, 03:41:55)
[GCC 7.3.0]
Enet4, chrisranderson, matkoniecz, im-shinomiya, punkeel and 1 more
Metadata
Metadata
Assignees
Labels
Enhancement ✨Improvement to a componentImprovement to a componentGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributors