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 positive with nonlocal #5965

Closed
darintay opened this issue Mar 24, 2022 · 1 comment · Fixed by #5966
Closed

used-before-assignment false positive with nonlocal #5965

darintay opened this issue Mar 24, 2022 · 1 comment · Fixed by #5966
Assignees
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code Regression
Milestone

Comments

@darintay
Copy link

Bug description

Getting a false positive for used-before-assignment in the latest pylint release when the variable is declared nonlocal. I don't think the new try/except logic is handling it correctly, I believe the code below is valid.

# pylint: disable=missing-docstring
def outer():
    myvar = 1
    def inner():
        nonlocal myvar
        try:
            print("A", myvar)
            raise IOError("emyvarc")
        except IOError:
            print("B", myvar)
            myvar += 1
            print("C", myvar)
    inner()
outer()
test.py:7:23: E0601: Using variable 'myvar' before assignment (used-before-assignment)

Configuration

No response

Command used

pylint a.py

Pylint output

test.py:7:23: E0601: Using variable 'myvar' before assignment (used-before-assignment)

Expected behavior

No pylint errors raised

Pylint version

pylint 2.13.0
astroid 2.11.1
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21) 
[GCC 9.4.0]

OS / Environment

Ubuntu 18.04

Additional dependencies

No response

@darintay darintay added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 24, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report, regression in #5402.

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 Positive 🦟 A message is emitted but nothing is wrong with the code Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants