Open
Description
Bug Report
In some cases (see code below) mypy recognizes type of values in nested dict as object
. Adding hint with more exact type results in an error.
To Reproduce
from typing import Union
key = 'foo'
x: dict[str, Union[str, bool]] = {
'foo': {
'key1': 'value',
'key2': True,
},
'bar': {
'key3': 'value',
'key4': False,
},
}[key]
Expected Behavior
mypy should not raise any error.
Actual Behavior
main.py:4: error: Incompatible types in assignment (expression has type "Dict[str, object]", variable has type "Dict[str, Union[str, bool]]")
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.971
- Python version used: 3.11
- Operating system: Linux