Python 3.11, mypy 1.15.0
Simple setup.
test.py:
from test_package import weird_symbol
def test(d: weird_symbol[str, list[int]]):
print(d.items())
reveal_type(d)
test_package
located in site-packages
that has 3 files: __init__.py
, py.typed
(both just empty files) and __init__.pyi
:
from collections import defaultdict as weird_symbol
__all__ = ['weird_symbol']
Running mypy check on this have this result:
> py -3.11 -m mypy test.py
test.py:5: note: Revealed type is "collections.defaultdict[builtins.str, builtins.list[builtins.int]]"
Success: no issues found in 1 source file
But if we mess with a stub file a bit making it import unknown symbol
from collections_ import defaultdict as weird_symbol
__all__ = ['weird_symbol']
There will be no errors, it will just interpret unknown symbol as Any
. Is it normal? I expected it to fail at least in some way indicating that there’s a missing symbol.
py -3.11 -m mypy test.py
test.py:5: note: Revealed type is "Any"
Success: no issues found in 1 source file
Why it’s important - noticed this because one of the files had something like from typing import TypeIs
(which is only available in Python 3.12) which led to some false negatives because some symbols were just replaced with Any
and had no real effect.