Open
Description
Bug Report
I noticed a strange behavior and inconsistency when first argument of typing_extensions.assert_type
is not defined.
To Reproduce
First case:
## a.py
def f() -> None:
from typing_extensions import assert_type
class X:
pass
# x = X() # note this line is commented out
assert_type(x, X)
## b.py
from a import X
reveal_type(X)
# Revealed type is "def () -> a.X@5"
Second case:
## a.py
def f() -> None:
from typing_extensions import assert_type
class X:
pass
x = X() # note this line is not commented out
assert_type(x, X)
## b.py
from a import X
reveal_type(X)
# Module "a" has no attribute "X"
# Revealed type is "Any"
To reproduce run mypy b.py
.
This snippets differ by only one line x = X()
, but mypy behavior is very different. It gives me module has no attribute
error, or gives no error.
Expected Behavior
I expect to get the Module "a" has no attribute "X"
error in both cases
My Environment
mypy 0.961 (compiled: no)
- no command-line flags, no config file
CPython 3.10.4
- Windows 10