-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Milestone
Description
Bug description
# tmp.py
if len((x for x in [1, 2, 3])): # this code emits a TypeError
print("yay!")
Command used
uvx pylint --disable=all --enable=C1802 tmp.py
Pylint output
************* Module tmp
tmp.py:1:3: C1802: Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty (use-implicit-booleaness-not-len)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 2.50/10, +2.50)
Expected behavior
No lint emitted. This should be a different error - len
is not defined for generators in the first place. Notice, for example, that no lint is emitted for length used as condition with other standard Python objects that do not admit lengths (e.g. lambda expressions or functions).
Pylint version
pylint 3.3.1
astroid 3.3.5
Python 3.11.5 (main, Sep 8 2023, 16:31:47) [Clang 14.0.3 (clang-1403.0.22.14.1)]
Metadata
Metadata
Assignees
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation