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

Emit used-before-assignment instead of undefined-variable for unused type annotations #5713

Closed
jacobtylerwalls opened this issue Jan 24, 2022 · 2 comments · Fixed by #5718
Closed
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Jan 24, 2022

Bug description

I think we can raise a more appropriate message for cases like:

def type_annotation_used_improperly_after_comprehension():
    """https://github.com/PyCQA/pylint/issues/5654"""
    my_int: int
    _ = [print(sep=my_int, end=my_int) for my_int in range(10)]  <--should be used-before-assignment
    print(my_int)  # [undefined-variable]

Because the python interpreter produces:

UnboundLocalError: local variable 'my_int' referenced before assignment

This feature was added in #5158, so perhaps recent enough to change, but not sure if it's too much churn/worth it to bother.

Expected behavior

Raise used-before-assignment instead of unused-variable for the above test from undefined_variable_py38.py

Pylint version

pylint 2.13.0-dev0
astroid 2.9.3
Python 3.10.1 (v3.10.1:2cd268a3a9, Dec  6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)]
@jacobtylerwalls jacobtylerwalls added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 24, 2022
@DanielNoord
Copy link
Collaborator

Could it be that the example is different than the error raised? What is my_none referring to?

@jacobtylerwalls
Copy link
Member Author

Sorry, typo in the report. I fixed it to match.

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 24, 2022
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 25, 2022
…ned-variable` when accessing unused type annotations
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 25, 2022
…ned-variable` when accessing unused type annotations
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 25, 2022
…ned-variable` when accessing unused type annotations
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 25, 2022
Pierre-Sassoulas pushed a commit that referenced this issue Jan 26, 2022
…le` when accessing unused type annotations (#5718)

* Add confidence level HIGH to  `used-before-assignment`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
3 participants