Skip to content

False positive used-before-assignment with try/else #6790

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

Closed
mattclay opened this issue Jun 1, 2022 · 2 comments · Fixed by #6791
Closed

False positive used-before-assignment with try/else #6790

mattclay opened this issue Jun 1, 2022 · 2 comments · Fixed by #6791
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
Milestone

Comments

@mattclay
Copy link

mattclay commented Jun 1, 2022

Bug description

The used-before-assignment check reports a false positive with try/else starting with pylint 2.13.0.

"""bug.py"""


def demo():
    """Demonstrate used-before-assignment regression in pylint 2.13.0 and later."""
    try:
        pass
    except ValueError:
        error = True
    else:
        return

    print(error)

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:13:10: E0601: Using variable 'error' before assignment (used-before-assignment)

Expected behavior

No errors reported, as was the case for 2.12.2.

Pylint version

pylint 2.14.0
astroid 2.11.5
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0]

OS / Environment

Ubuntu 22.04.4

Additional dependencies

No response

@mattclay mattclay added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 1, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the well-written report. I have a diff for this that if all goes well we should be able to backport to 2.14.1.

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 1, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.14.1 milestone Jun 1, 2022
@mattclay
Copy link
Author

mattclay commented Jun 2, 2022

@jacobtylerwalls Thanks for responding so quickly. I've opened a related issue (#6804) which involves continue instead of return, in case you want to treat them as separate issues.

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
Projects
None yet
2 participants