ruff/crates/red_knot_python_semantic/resources/mdtest
TomerBin 6c56a7a868
[red-knot] Implement type narrowing for boolean conditionals (#14037)
## Summary

This PR enables red-knot to support type narrowing based on `and` and
`or` conditionals, including nested combinations and their negation (for
`elif` / `else` blocks and for `not` operator). Part of #13694.

In order to address this properly (hopefully 😅), I had to run
`NarrowingConstraintsBuilder` functions recursively. In the first commit
I introduced a minor refactor - instead of mutating `self.constraints`,
the new constraints are now returned as function return values. I also
modified the constraints map to be optional, preventing unnecessary
hashmap allocations.
Thanks @carljm for your support on this :)

The second commit contains the logic and tests for handling boolean ops,
with improvements to intersections handling in `is_subtype_of` .

As I'm still new to Rust and the internals of type checkers, I’d be more
than happy to hear any insights or suggestions.
Thank you!

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2024-11-04 22:54:35 +00: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] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00: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] Infer subscript expression types for bytes literals (#13901) 2024-10-24 12:07:41 +02: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] Remove lint-phase (#13922) 2024-10-25 18:40:52 +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