astral-sh
ruff
BlogDocsChangelog

Performance History

Latest Results

[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.
bxff:fix-enum-custom-eq-narrowing
2 hours ago

Active Branches

[ty] Fix narrowing for transparent enums (StrEnum, IntEnum)
last run
2 hours ago
#22690
CodSpeed Performance Gauge
-94%
#22687
CodSpeed Performance Gauge
+1%
© 2026 CodSpeed Technology
Home Terms Privacy Docs