ruff/crates/red_knot_python_semantic
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
..
resources [red-knot] Implement type narrowing for boolean conditionals (#14037) 2024-11-04 22:54:35 +00:00
src [red-knot] Implement type narrowing for boolean conditionals (#14037) 2024-11-04 22:54:35 +00:00
tests [red-knot] Cleanup generated names of mdtest tests (#13831) 2024-10-20 15:11:53 +00:00
build.rs Modernize build scripts (#13837) 2024-10-20 22:35:35 +01:00
Cargo.toml Avoid cloning Name when looking up function and class types (#14092) 2024-11-04 15:52:59 +01:00