Skip to content

used-before-assignment false positive for type alias #9815

Open
@nickdrozd

Description

@nickdrozd

Bug description

type IntOrX = int | X

class X:
    pass

Configuration

No response

Command used

pylint --py-version=3.12 asdf.py

Pylint output

asdf.py:1:20: E0601: Using variable 'X' before assignment (used-before-assignment)

Expected behavior

No warning

The value of the type alias is evaluated in the annotation scope. It is not evaluated when the type alias is created, but only when the value is accessed through the type alias’s value attribute (see Lazy evaluation). This allows the type alias to refer to names that are not yet defined.

https://docs.python.org/3/reference/simple_stmts.html#the-type-statement

Pylint version

pylint 3.3.0-dev0
astroid 3.3.0-dev0
Python 3.12.3

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationpython 3.12typing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions