-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-typed-dict
Description
Bug Report
This bug is a bit hard to describe, so you should take a look at the test code. Feel free to edit the title.
As you can see in the test code, a expects dict[Literal["exclude"], list[str]]. test_dict, which is passed to b has a opional key named key with this type. As this type is optional, we use get here. Get returns {"exclude": []}) in case key does not exists in test_dict. {"exclude": []}) fits the type dict[Literal["exclude"], list[str]] but Mypy think it does not fit.
This bug does not exists in Mypy 1.17.
To Reproduce
https://mypy-play.net/?mypy=1.18.2&python=3.12&gist=932063170e6ad2c3ab798153870b82d4
Expected Behavior
Mypy should not find any errors
Actual Behavior
main.py:13: error: Argument 1 to "a" has incompatible type "dict[Literal['exclude'], list[str]] | dict[str, list[Never]]"; expected "dict[Literal['exclude'], list[str]]" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.18.2
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.13.7
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-typed-dict