pylint icon indicating copy to clipboard operation
pylint copied to clipboard

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

Open hydrargyrum opened this issue 1 month ago • 0 comments

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 avatar May 17 '24 09:05 hydrargyrum