ruff
9333f154 - [ty] Fix match exhaustiveness for enum | None unions (#22290)

Commit
4 days ago
[ty] Fix match exhaustiveness for enum | None unions (#22290) ## Summary If we match on an `TestEnum | None`, then when adding a case like `~Literal[TestEnum.FOO]` (i.e., after `if value == TestEnum.FOO: return`), we'd distribute `Literal[TestEnum.BAR]` on the entire builder, creating `None & Literal[TestEnum.BAR]` which simplified to `Never`. Instead, we should only expand to the remaining members for pieces of the intersection that contain the enum. Now, `(TestEnum | None) & ~Literal[TestEnum.FOO] & ~Literal[TestEnum.BAR]` correctly simplifies to `None` instead of `Never`. Closes https://github.com/astral-sh/ty/issues/2260.
Author
Parents
Loading