Skip to content

False positive from used-before-assignment when variable is reimported #7882

Closed
@MarcoGorelli

Description

@MarcoGorelli

Bug description

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from foo import Bar

def myfunc():
    result: Bar

    from foo import Bar # if I remove this, then no error is reported

Note how if I remove the from foo import Bar line, then the error goes away

Command used

pylint --disable=all --enable=used-before-assignment t.py

Pylint output

************* Module t
t.py:7:12: E0601: Using variable 'Bar' before assignment (used-before-assignment)

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

Expected behavior

No error reported

Pylint version

pylint 2.15.7
astroid 2.12.13
Python 3.8.15 (default, Oct 12 2022, 19:15:16) 
[GCC 11.2.0]

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 codeGood first issueFriendly and approachable by new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions