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

False positive used-before-assignment with try/else/continue #6804

Closed
mattclay opened this issue Jun 2, 2022 · 1 comment · Fixed by #9374
Closed

False positive used-before-assignment with try/else/continue #6804

mattclay opened this issue Jun 2, 2022 · 1 comment · Fixed by #9374
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@mattclay
Copy link

mattclay commented Jun 2, 2022

Bug description

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

This issue is nearly identical to #6790, except it involves continue instead of return.

"""bug.py"""


def demo():
    """Demonstrate used-before-assignment regression in pylint==2.13.0 and 2.14.0."""
    for _temp in range(0, 1):
        try:
            pass
        except ValueError:
            error = True
        else:
            continue

        print(error)

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:14:14: 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 2, 2022
@jacobtylerwalls jacobtylerwalls added Control flow Requires control flow understanding 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 2, 2022
@jacobtylerwalls
Copy link
Member

This one's harder because depending on error is not safe if attempted outside the loop, so my hope would be to distinguish the two cases.

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 Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants