-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
mypy incorrectly calculates the type of emun if its value is checked with tuple().__contains__ in "if" clause.
To Reproduce
https://gist.github.com/mypy-play/e316d3d5b495cb113cacc9c55136dea7
Expected Behavior
main.py:10: note: Revealed type is "Literal[__main__.Op.A]"
main.py:13: note: Revealed type is "Literal[__main__.Op.B]"
Actual Behavior
main.py:10: note: Revealed type is "__main__.Op"
main.py:13: note: Revealed type is "Literal[__main__.Op.B]"
main.py:16: error: Argument 1 to "assert_never" has incompatible type "Literal[Op.A]"; expected "Never" [arg-type]
Pyright works fine with it - https://pyright-play.net/?code=JYWwDg9gTgLgBAUwHYFcQChSVnGBPMYJAc3XQGMAbAQwGda4B5MACmTQDoBRVEASgBc6OCLgBBOAF44AImozhogEJTZAIwXoAJggBmcKCiQsIYAUzCDFI4PtNwicFsw5iANFdFfcBIsQ5QCABuCNSUAPr4YAgmltbegTAoUEjxCJS2cPaS0i5KQt6iUX4BwaERUTGmfPFeicmpXum0CAWFPoQkHHQtsOFIZVCxNUA.
Your Environment
- Mypy version used: 1.18.2
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder