Bug Report
When comparing a member of StrEnum to a string, it seems that Mypy assumes that the check is always False and does not type-check code under the condition.
To Reproduce https://mypy-play.net/?mypy=latest&python=3.12&gist=f7c8364d301ada4067a9a6f515b9e161
import typing import enum class MyEnum(str, enum.Enum): A = 'a' class MyEnum2(enum.StrEnum): A = 'a' if MyEnum.A == 'a': 1 + '' if MyEnum2.A == 'a': 1 + ''
Expected Behavior
Mypy should flag both 1 + '' expressions as type errors because these conditions evaluate to True in runtime.
Actual Behavior
Mypy does not report errors
Your Environment
cc @sobolevn maybe
Rework narrowing logic for equality and identity (python#20492)
Activity
A5rocks commented on Mar 17, 2025
cc @sobolevn maybe
Rework narrowing logic for equality and identity (python#20492)