ruff
74bf4b06 - [red knot] Fix narrowing for '… is not …' type guards, add '… is …' type guards (#13758)

Commit
1 year ago
[red knot] Fix narrowing for '… is not …' type guards, add '… is …' type guards (#13758) ## Summary - Fix a bug with `… is not …` type guards. Previously, in an example like ```py x = [1] y = [1] if x is not y: reveal_type(x) ``` we would infer a type of `list[int] & ~list[int] == Never` for `x` inside the conditional (instead of `list[int]`), since we built a (negative) intersection with the type of the right hand side (`y`). However, as this example shows, this assumption can only be made for singleton types (types with a single inhabitant) such as `None`. - Add support for `… is …` type guards. closes #13715 ## Test Plan Moved existing `narrow_…` tests to Markdown-based tests and added new ones (including a regression test for the bug described above). Note that will create some conflicts with https://github.com/astral-sh/ruff/pull/13719. I tried to establish the correct organizational structure as proposed in https://github.com/astral-sh/ruff/pull/13719#discussion_r1800188105
Author
Parents
Loading