Skip to content

E0601: used-before-assignment false positive for import under TYPE_CHECKING check #7368

Closed
@Rogdham

Description

@Rogdham

Bug description

# pylint: disable=missing-module-docstring, missing-function-docstring

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from typing_extensions import assert_type
else:

    def assert_type(val, _):
        return val

ANSWER = 42
assert_type(ANSWER, int)

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:13:0: E0601: Using variable 'assert_type' before assignment (used-before-assignment)

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

Expected behavior

This is a false positive, as assert_type is defined in both branches of the if.

Pylint version

pylint 2.15.0
astroid 2.12.4
Python 3.10.6 (main, Aug  3 2022, 17:39:45) [GCC 12.1.1 20220730]

OS / Environment

Archlinux

Additional dependencies

astroid==2.12.4
dill==0.3.5.1
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.7.0
platformdirs==2.5.2
pylint==2.15.0
tomli==2.0.1
tomlkit==0.11.4
wrapt==1.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkControl flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds 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