ruff/crates/red_knot_python_semantic/resources/mdtest
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
..
annotations [red-knot] Do not panic when encountering string annotations (#14091) 2024-11-04 15:06:54 +01:00
assignment [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
binary [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
boolean [red-knot] Remove Type::Unbound (#13980) 2024-10-31 20:05:53 +01:00
call [red-knot] Remove lint-phase (#13922) 2024-10-25 18:40:52 +00:00
comparison [red-knot] Precise inference for identity checks (#14109) 2024-11-05 19:48:52 +01:00
conditional [red-knot] Remove Type::Unbound (#13980) 2024-10-31 20:05:53 +01:00
declaration [red-knot] Remove lint-phase (#13922) 2024-10-25 18:40:52 +00:00
exception [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
expression [red-knot] Infer type of if-expression if test has statically known truthiness (#14048) 2024-11-01 12:23:18 -07:00
import [red-knot] Remove Type::Unbound (#13980) 2024-10-31 20:05:53 +01:00
literal [red-knot] Literal special form (#13874) 2024-11-05 01:45:46 +00:00
loops [red-knot] Remove Type::Unbound (#13980) 2024-10-31 20:05:53 +01:00
narrow [red-knot] Implement type narrowing for boolean conditionals (#14037) 2024-11-04 22:54:35 +00:00
scopes [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
shadowing [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
stubs [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
subscript [red-knot] Infer type of if-expression if test has statically known truthiness (#14048) 2024-11-01 12:23:18 -07:00
unary [red-knot] Literal special form (#13874) 2024-11-05 01:45:46 +00:00
with [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
.mdformat.toml [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
attributes.md [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
generics.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
mro.md [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
unpacking.md [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00