Skip to content

False positive used-before-assignment for variable annotations when using TYPE_CHECKING #7609

Closed
@mew1033

Description

@mew1033

Bug description

I know this has been looked at before, but I just ran into it again with pylint 2.15.4. If an import is guarded behind TYPE_CHECKING, I'm getting an used-before-assignment error when using that import in a type definition.

Configuration

No response

Command used

pylint file.py

Pylint output

file.py:7:19: E0601: Using variable 'PublishBatchRequestEntryTypeDef' before assignment (used-before-assignment)

Expected behavior

It shouldn't error

Pylint version

pylint 2.15.4
astroid 2.12.11
Python 3.9.14 (main, Sep  7 2022, 23:43:29) 
[GCC 9.4.0]

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 implementationtyping

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions