-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
E0601: used-before-assignment
false positive for import under TYPE_CHECKING
check
#7368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The issue is still here if the import is from stdlib instead of an external module: # pylint: disable=missing-module-docstring, missing-function-docstring
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections import defaultdict
else:
def defaultdict():
return {}
defaultdict()
|
Good catch. 3159b17 only checked |
@jacobtylerwalls Just for my understanding, why are we special-casing # pylint: disable=missing-module-docstring, missing-function-docstring
from typing import value
if value:
from typing_extensions import assert_type
else:
def assert_type(val, _):
return val
ANSWER = 42
assert_type(ANSWER, int) This doesn't raise, only a |
Assignments under if TYPE_CHECKING are always false at runtime, so from the perspective of |
@jacobtylerwalls I did what I could in #7370, but the |
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
This is a false positive, as
assert_type
is defined in both branches of theif
.Pylint version
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
The text was updated successfully, but these errors were encountered: