Open JakobDev opened 1 year ago
I had very similar code:
some_dict: dict = {}
if isinstance(some_dict.get('a_key'), dict):
reveal_type(some_dict['a_key']) # Revealed type is "Any"
rewriting it to a more verbose
some_dict: dict = {}
if 'a_key' in some_dict and isinstance(some_dict['a_key'], dict):
reveal_type(some_dict['a_key']) # Revealed type is "builtins.dict[Any, Any]"
suffices as a workaround, but I would much prefer the shorter expression.
Bug Report
See Code and Explanation below
To Reproduce
Playground Link
Expected Behavior According to the TypedDict, we have 3 cases for the Key
my_optional_dict
:total=False
None
DictA
If we look at the if in the
test
function, it does 2 things:This means, that the
my_optional_dict
ofarg
is always of the typeDictA
, so mypy should not see a problem here.Actual Behavior
Your Environment
mypy.ini
(and other config files): None