ruff
22966275 - [red-knot] Precise inference for identity checks (#14109)

Commit
1 year ago
[red-knot] Precise inference for identity checks (#14109) ## Summary Adds more precise type inference for `… is …` and `… is not …` identity checks in some limited cases where we statically know the answer to be either `Literal[True]` or `Literal[False]`. I found this helpful while working on type inference for comparisons involving intersection types, but I'm not sure if this is at all useful for real world code (where the answer is most probably *not* statically known). Note that we already have *type narrowing* for identity tests. So while we are already able to generate constraints for things like `if x is None`, we can now — in some limited cases — make an even stronger conclusion and infer that the test expression itself is `Literal[False]` (branch never taken) or `Literal[True]` (branch always taken). ## Test Plan New Markdown tests
Author
Parents
Loading