-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
The revealed narrowed type is unexpected, and there is a false negative:
from enum import IntEnum
class E(IntEnum):
X = 1
def f(x: int) -> None:
if x == E.X:
print(x.value) # No mypy error, but fails at runtime
reveal_type(x) # "Literal[E.X]"
f(1)I'd expect the revealed type to be int, since that's the correct runtime type. IntEnum values are equal to the corresponding int objects:
print(1 == E.X) # TrueAlso, x.value should be flagged as an error, since it fails at runtime.
If this needs special casing for IntEnums, it's fine. We already special case enums in various ways.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder