ruff/crates/red_knot_python_semantic/resources/mdtest/comparison
David Peter 2296627528
[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
2024-11-05 19:48:52 +01:00
..
instances [red-knot] Literal special form (#13874) 2024-11-05 01:45:46 +00:00
byte_literals.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
identity_tests.md [red-knot] Precise inference for identity checks (#14109) 2024-11-05 19:48:52 +01:00
integers.md [red-knot] Type inference for comparisons between arbitrary instances (#13903) 2024-10-26 18:19:56 +00:00
non_boolean_returns.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
strings.md [red-knot] Format mdtest Python snippets more concisely (#13905) 2024-10-24 11:09:31 +00:00
tuples.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
unions.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
unsupported.md [red-knot] Type inference for comparisons between arbitrary instances (#13903) 2024-10-26 18:19:56 +00:00