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 for homonym between subscript in comprehension and assignment in except block #6069

Closed
jacobtylerwalls opened this issue Mar 31, 2022 · 0 comments · Fixed by #6073
Assignees
Labels
Bug 🪲 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

@jacobtylerwalls
Copy link
Member

False positive for used-before-assignment from subscript notation in comprehension followed by definition of that same variable later in an except block.

# test.py
def select_dict(data, keys):
    try:
        d = {key: data[key] for key in keys}
    except KeyError as e:
        key, *_ = e.args
        raise Exception(f"{key} not found")

    return d
$ pip install -U pylint==2.13.4 -q && pylint test.py
************* Module test
test.py:3:23: E0601: Using variable 'key' before assignment (used-before-assignment)

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

Originally posted by @skshetry in #6035 (comment)

@jacobtylerwalls jacobtylerwalls self-assigned this Mar 31, 2022
@jacobtylerwalls jacobtylerwalls added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check labels Mar 31, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.13.5 milestone Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 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
1 participant