ruff
5a55bab3 - [ty] Infer single-valuedness for enums based on `int`/`str` (#19510)

Commit
142 days ago
[ty] Infer single-valuedness for enums based on `int`/`str` (#19510) ## Summary We previously didn't recognize `Literal[Color.RED]` as single-valued, if the enum also derived from `str` or `int`: ```py from enum import Enum class Color(str, Enum): RED = "red" GREEN = "green" BLUE = "blue" def _(color: Color): if color == Color.RED: reveal_type(color) # previously: Color, now: Literal[Color.RED] ``` The reason for that was that `int` and `str` have "custom" `__eq__` and `__ne__` implementations that return `bool`. We do not treat enum literals from classes with custom `__eq__` and `__ne__` implementations as single-valued, but of course we know that `int.__eq__` and `str.__eq__` are well-behaved. ## Test Plan New Markdown tests.
Author
Parents
Loading