Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use-implicit-booleaness-not-len [C1802] should not be emitted for generators #10100

Open
dylwil3 opened this issue Nov 25, 2024 · 0 comments
Open
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@dylwil3
Copy link

dylwil3 commented Nov 25, 2024

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)]
@dylwil3 dylwil3 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 25, 2024
@zenlyj zenlyj added Good first issue Friendly and approachable by new contributors False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants