ruff
a3c71eb7 - [ty] Fix narrowing enum literal unions by member identity (#25520)

Commit
57 days ago
[ty] Fix narrowing enum literal unions by member identity (#25520) ## Summary Prior to this change, we failed to narrow a union containing an explicitly annotated enum literal (e.g., `x: list[int] | Literal[Answer.NO]`) when comparing it against the corresponding enum member: ```python from enum import Enum from typing import Literal class Answer(Enum): NO = 0 YES = 1 def f(x: list[int] | Literal[Answer.NO]): if x is Answer.NO: return # Before: list[int] | Literal[Answer.NO] # After: list[int] reveal_type(x) ``` We were comparing the outer literal types, so the intersection builder failed to recognize that both types represented the same enum member. Now, we compare the underlying enum-literal identities instead, restoring narrowing for `is`, `is not`, `==`, and `!=`. Closes https://github.com/astral-sh/ty/issues/3606.
Author
Parents
Loading