Skip to content

Error "undefined-variable" for TYPE_CHECKING code #10778

@Flamefire

Description

@Flamefire

Bug description

Using the common pattern of importing types only in `TYPE_CHECKING` mode causes an E0602:


# pylint: disable=missing-docstring,

TYPE_CHECKING = False
if TYPE_CHECKING:
    from typing import IO

def conv(o: Any) -> str:
    return str(o)

Configuration

Command used

pylint /tmp/test.py

Pylint output

************* Module test
/tmp/test.py:7:12: E0602: Undefined variable 'Any' (undefined-variable)

Expected behavior

No error

Pylint version

pylint 3.3.9
astroid 3.3.8
Python 3.9.18 (main, Sep 17 2024, 16:28:06)

OS / Environment

No response

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions