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

Pylint does not catch simple case of UnboundLocalError (variable-undefined/used-before-assignment) #9373

Closed
milosivanovic opened this issue Jan 19, 2024 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@milosivanovic
Copy link

milosivanovic commented Jan 19, 2024

Pylint does not catch a simple case of variable-undefined and/or used-before-assignment:

Bug description

def func():
    if False:
        chk = "something"
    else:
        print(chk)

func()

When executed, the else block in the above example would raise UnboundLocalError: cannot access local variable 'chk' where it is not associated with a value

Is this a regression of #4045 and #5811?

Configuration

No response

Command used

pylint --disable=using-constant-test,missing-module-docstring,missing-function-docstring

Pylint output

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

Expected behavior

Pylint should easily catch chk as used-before-assignment and/or undefined-variable

Pylint version

pylint 3.0.3
astroid 3.0.2
Python 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]

OS / Environment

macOS Sonoma 14.2.1 (23C71)

Additional dependencies

No response

@milosivanovic milosivanovic added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 19, 2024
@jacobtylerwalls
Copy link
Member

Duplicate of #1727

Happy to have your review of the PR to close it!

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2024
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants