ruff
6c56a7a8 - [red-knot] Implement type narrowing for boolean conditionals (#14037)

Commit
1 year ago
[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>
Author
Parents
Loading