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

[used-before-assignment] False negative for name defined inside loop that never runs #9642

Open
hydrargyrum opened this issue May 17, 2024 · 0 comments
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@hydrargyrum
Copy link

hydrargyrum commented May 17, 2024

Bug description

"""doc"""

def f():
    """doc"""

    for i in []:
        if i:
            fail1 = 42
    print(fail1)  # bug detected

    for i in []:
        fail2 = 42
    print(fail2)  # bug not detected

Configuration

No response

Command used

pylint bad.py

Pylint output

************* Module bad
bad.py:9:10: E0606: Possibly using variable 'fail1' before assignment (possibly-used-before-assignment)

------------------------------------------------------------------
Your code has been rated at 3.75/10 (previous run: 3.75/10, +0.00)

Expected behavior

line 13 should also have possibly-used-before-assignment for fail2

Pylint version

pylint 3.2.0
astroid 3.2.1
Python 3.11.9

OS / Environment

No response

Additional dependencies

No response

@hydrargyrum hydrargyrum added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 17, 2024
@jacobtylerwalls jacobtylerwalls changed the title E0606 not detected in a simple loop [used-before-assignment] False negative for name defined inside loop that never runs May 17, 2024
@jacobtylerwalls jacobtylerwalls added False Negative 🦋 No message is emitted but something is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check 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 May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants