astral-sh
ruff
BlogDocsChangelog

Branches performance

Pull requests

[ty] Fix narrowing for transparent enums (StrEnum, IntEnum)#22690
last run
59 minutes ago
[ty] Fix narrowing for transparent enums (StrEnum, IntEnum) ## Summary This PR fixes incorrect type narrowing to Never for enums with transparent equality semantics, such as StrEnum and IntEnum. These enums compare equal to their underlying primitive values at runtime, but the type checker previously treated them as disjoint. The fix introduces a has_transparent_equality helper to identify enums inheriting from primitive types (str, int, or bytes). It then updates disjointness checks and intersection logic to recognize that these enum members are not disjoint from matching primitive literals. This ensures that narrowing in match statements and comparisons correctly preserves the appropriate types instead of collapsing to Never. This directly resolves ty#1454 by improving the core type relation and builder logic. By explicitly detecting transparent enums, this solution is more resilient than relying on overrides_equality which is currently affected by pre-existing lookup policy bugs. Closes https://github.com/astral-sh/ty/issues/1454. ## Test Plan I added a new test file match_enums.md with regression cases for: - StrEnum narrowing in match statements. - Handling of enums with custom __eq__ overrides (narrowing disabled). - Tagged union narrowing with StrEnum in TypedDict fields. I also verified that all existing enum and narrowing tests pass and that there are no regressions in the semantic type checker's unit tests.
1 hour ago
4e503b2
bxff:fix-enum-custom-eq-narrowing
CodSpeed Performance Gauge
-94%
[ty] diagnostic on overridden comparison dunder methods on order=True dataclasses https://github.com/astral-sh/ty/issues/111
1 hour ago
306daf0
thejchap:thejchap/ordering2
CodSpeed Performance Gauge
0%
[ty] Avoid reporting overload errors for successful union variants
2 hours ago
9fa25f8
charlie/success
CodSpeed Performance Gauge
0%
[ty] Avoid overload errors when detecting dataclass-on-tuple
3 hours ago
6993da4
charlie/data-decorator
CodSpeed Performance Gauge
+1%
© 2026 CodSpeed Technology
Home Terms Privacy Docs