David Peter
5a55bab3f3
[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.
2025-07-23 15:55:42 +02:00
..
2025-07-22 16:10:38 +02:00
2025-06-20 18:23:54 -04:00
2025-06-20 18:23:54 -04:00
2025-05-17 08:27:32 -04:00
2025-05-06 20:11:25 -04:00
2025-07-23 13:06:30 +02:00
2025-05-06 20:11:25 -04:00
2025-07-15 21:31:53 +02:00
2025-05-03 19:49:15 +02:00
2025-07-15 21:31:53 +02:00
2025-07-21 20:51:58 +02:00
2025-06-26 14:29:33 +02:00
2025-07-15 16:56:54 -07:00
2025-07-04 11:52:52 -07:00
2025-05-09 13:40:51 -04:00
2025-06-12 07:44:42 -07:00
2025-07-21 21:25:11 +00:00
2025-07-16 14:48:04 -06:00
2025-06-29 10:46:33 +00:00
2025-07-15 21:31:53 +02:00
2025-07-15 16:56:54 -07:00
2025-05-09 17:39:15 +01:00
2025-05-03 19:49:15 +02:00
2025-07-22 14:33:08 -04:00
2025-05-03 19:49:15 +02:00
2025-07-22 16:42:10 -07:00
2025-05-03 19:49:15 +02:00
2025-07-21 14:01:42 +01:00
2025-05-22 21:37:03 -04:00
2025-06-24 18:39:02 +00:00
2025-07-22 16:10:38 +02:00
2025-07-21 21:25:11 +00:00
2025-07-15 21:31:53 +02:00
2025-07-23 15:55:42 +02:00
2025-07-22 14:21:29 +02:00
2025-05-06 20:11:25 -04:00
2025-05-26 21:34:47 +02:00
2025-05-03 19:49:15 +02:00
2025-07-21 19:37:55 +02:00
2025-05-13 21:27:48 +00:00
2025-05-09 13:40:51 -04:00
2025-07-18 14:58:32 -07:00
2025-07-22 16:10:38 +02:00
2025-07-05 19:34:23 +01:00
2025-07-23 08:46:51 +02:00
2025-07-23 13:06:30 +02:00
2025-05-03 19:49:15 +02:00
2025-06-24 20:27:37 +00:00
2025-07-21 19:37:55 +02:00
2025-05-03 19:49:15 +02:00
2025-05-03 19:49:15 +02:00
2025-05-03 19:49:15 +02:00
2025-05-06 12:37:10 +01:00
2025-05-06 20:11:25 -04:00
2025-05-26 20:40:16 +01:00
2025-06-03 09:59:43 -07:00
2025-06-20 10:38:17 +02:00
2025-05-19 16:36:49 +02:00
2025-05-09 13:40:51 -04:00
2025-07-22 16:10:38 +02:00
2025-06-26 12:24:40 +02:00
2025-06-26 12:24:40 +02:00
2025-05-03 19:49:15 +02:00
2025-05-03 19:49:15 +02:00
2025-07-04 11:52:52 -07:00
2025-06-24 18:02:05 -07:00
2025-07-15 12:47:19 +01:00
2025-07-21 19:37:55 +02:00
2025-06-27 15:29:04 -04:00
2025-06-26 12:24:40 +02:00