Closed
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)]