Open
Description
Bug Report
Mypy reports [valid-type]
for a variable defined in the same file but not when the variable is imported in other files.
To Reproduce
Create 3 files
# app/example_a.py
def dynamic_type(x):
return type("some_type", () , x)
# app/example_b.py
from app.example_a import dynamic_type
SOME_FAKE_TYPE = dynamic_type({"a": "a"})
x: SOME_FAKE_TYPE
# app/example_c.py
from app.example_b import SOME_FAKE_TYPE
x: SOME_FAKE_TYPE
Expected Behavior
Mypy should raise [valid-type]
errors in both app/example_b.py
and app/example_c.py
Actual Behavior
It only reports [valid-type]
errors in app/example_b.py
app/example_b.py:6: error: Variable "app.example_b.SOME_FAKE_TYPE" is not valid as a type [valid-type]
app/example_b.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Your Environment
$ uv run mypy --version
mypy 1.16.0 (compiled: yes
- Mypy version used: 1.16.0
- Mypy command-line flags:
mypy
- Mypy configuration options from
mypy.ini
(and other config files):
[mypy]
check_untyped_defs = True
follow_imports = normal
disallow_untyped_defs = False
files = app/
- Python version used: 3.11.8