mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-04 23:50:31 +00:00
![]() ## 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. |
||
---|---|---|
.. | ||
resources | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml | ||
mdtest.py | ||
mdtest.py.lock |