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

Should emit used-before-assignment for unused type annotation after the same name appears multiple times in a comprehension #5654

Closed
jacobtylerwalls opened this issue Jan 8, 2022 · 1 comment · Fixed by #5711
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code
Milestone

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Jan 8, 2022

Bug description

"""https://github.com/PyCQA/pylint/issues/5654"""
from typing import Any
def func():
    """Should raise used-before-assignment on the last line"""
    my_none: Any
    _ = [print(sep=my_none, end=my_none) for my_none in (None, None)]
    print(my_none)

Configuration

No response

Command used

pylint a.py

Pylint output

On `main`, it's raised on the wrong line (the comprehension line):
test.py:5:37: E0602: Undefined variable 'my_none' (undefined-variable)

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

After #5651, no warnings at all:

$ pylint ../test.py

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

Expected behavior

test.py:7:37: E0601: Using variable 'my_none' before assignment (used-before-assignment)

Pylint version

pylint 2.13.0-dev0
astroid 2.9.2
Python 3.10.1 (v3.10.1:2cd268a3a9, Dec  6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)]

OS / Environment

No response

Additional dependencies

No response

@jacobtylerwalls jacobtylerwalls added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 8, 2022
@DanielNoord DanielNoord added C: undefined-variable Issues related to 'undefined-variable' check False Negative 🦋 No message is emitted but something is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 9, 2022
@jacobtylerwalls jacobtylerwalls changed the title Should emit undefined-variable for unused type annotation after the same name appears multiple times in a comprehension Should emit used-before-assignment for unused type annotation after the same name appears multiple times in a comprehension Jan 23, 2022
@jacobtylerwalls
Copy link
Member Author

Edited to suggest used-before-assignment because the Python interpreter produces:

UnboundLocalError: local variable 'my_none' referenced before assignment

@DanielNoord DanielNoord added C: used-before-assignment Issues related to 'used-before-assignment' check and removed C: undefined-variable Issues related to 'undefined-variable' check labels Jan 23, 2022
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 24, 2022
…sed type annotation after the same name appears multiple times in a comprehension
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 24, 2022
…unused type annotation after the same name appears multiple times in a comprehension
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 24, 2022
Pierre-Sassoulas added a commit that referenced this issue Jan 26, 2022
For unused type annotation after the same name appears multiple times in a comprehension

Fix #5654

Co-authored-by: Pierre Sassoulas <[email protected]>
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 Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
3 participants