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-except #5817

Closed
TTKuLa opened this issue Feb 17, 2022 · 2 comments · Fixed by #5818
Closed

False positive used-before-assignment with try-except #5817

TTKuLa opened this issue Feb 17, 2022 · 2 comments · Fixed by #5818
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

@TTKuLa
Copy link

TTKuLa commented Feb 17, 2022

Bug description

The following code will raise a used-before-assignment error:

def some_method():
    try:
        some_list = [e for e in (1, 2, 3) if e]  # Using variable 'e' before assignment!
    except Exception as e:
        pass

Configuration

No response

Command used

pylint used_before_assignment.py -E

Pylint output

************* Module used_before_assignment
used_before_assignment.py:3:45: E0601: Using variable 'e' before assignment (used-before-assignment)

Expected behavior

Expected no error, since the variable e in the try-except and the e in the list comprehension use different scopes.

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

@TTKuLa TTKuLa added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 17, 2022
@DanielNoord DanielNoord added C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 17, 2022
@Pierre-Sassoulas
Copy link
Member

Probably fixed in #5812 (duplicate of #5112 ?)

@jacobtylerwalls
Copy link
Member

No, it's unrelated! Pretty much the only except-related case in that method that I had not altered yet :-D

jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Mar 29, 2022
…ltered comprehensions

The prior fixes in pylint-dev#5586 and pylint-dev#5817 still relied on assumptions of direct parentage.
jacobtylerwalls added a commit that referenced this issue Mar 31, 2022
…onym handling

The previous fixes for false positives involving homonyms with variables in comprehension tests in
#5586 and #5817 still relied on assumptions of direct parentage.
Pierre-Sassoulas pushed a commit that referenced this issue Mar 31, 2022
…onym handling

The previous fixes for false positives involving homonyms with variables in comprehension tests in
#5586 and #5817 still relied on assumptions of direct parentage.
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
4 participants