Skip to content

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

Closed
@jacobtylerwalls

Description

@jacobtylerwalls

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)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions