-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
Related to #731
The new recursive types support (enabled by flag --enable-recursive-aliases) does not behave correctly.
To Reproduce
from typing import Dict, List, Union
JSON = Union[Dict[str, 'JSON'], List['JSON'], str, int, float, bool, None]
some_data = {'eggs': 'spam'}
json_data: JSON = {'foo': 'bar', 'python': some_data}Expected Behavior
The MyPy should not detect any errors since some_data is a valid JSON representation and can be safely nested in another JSON.
Actual Behavior
$ mypy --enable-recursive-aliases main.py
main.py:6: error: Dict entry 1 has incompatible type "str": "Dict[str, str]"; expected "str": "Union[Dict[str, JSON], List[JSON], str, float, None]"
Found 1 error in 1 file (checked 1 source file)Please note that explicitly marking some_data as JSON does not return the error, e.g.
from typing import Dict, List, Union
JSON = Union[Dict[str, 'JSON'], List['JSON'], str, int, float, bool, None]
some_data: JSON = {'eggs': 'spam'}
json_data: JSON = {'foo': 'bar', 'python': some_data} # no error detectedYour Environment
- Mypy version used:
0.981 - Mypy command-line flags:
--enable-recursive-aliases - Mypy configuration options from
mypy.ini(and other config files): - - Python version used:
3.10
smheidrich
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong