ruff/crates
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
..
red_knot Enable nursery rules: 'redundant_clone', 'debug_assert_with_mut_call', and 'unused_peekable' (#13920) 2024-10-25 09:46:30 +02:00
red_knot_python_semantic [red-knot] Implement type narrowing for boolean conditionals (#14037) 2024-11-04 22:54:35 +00:00
red_knot_server Enable nursery rules: 'redundant_clone', 'debug_assert_with_mut_call', and 'unused_peekable' (#13920) 2024-10-25 09:46:30 +02:00
red_knot_test Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
red_knot_vendored Sync vendored typeshed stubs (#14030) 2024-11-01 10:51:56 +00:00
red_knot_wasm Enable nursery rules: 'redundant_clone', 'debug_assert_with_mut_call', and 'unused_peekable' (#13920) 2024-10-25 09:46:30 +02:00
red_knot_workspace [red-knot] Remove lint-phase (#13922) 2024-10-25 18:40:52 +00:00
ruff Add links to missing related options within rule documentations (#13971) 2024-11-03 14:15:57 -05:00
ruff_benchmark [red-knot] Add MRO resolution for classes (#14027) 2024-11-04 13:31:38 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Give non-existent files a durability of at least Medium (#14034) 2024-11-01 16:44:30 +01:00
ruff_dev Alternate quotes for strings inside f-strings in preview (#13860) 2024-10-23 07:57:53 +02:00
ruff_diagnostics [Minor typo] Fix article in "an fix" (#12797) 2024-08-10 21:22:00 -04:00
ruff_formatter Join implicit concatenated strings when they fit on a line (#13663) 2024-10-24 11:52:22 +02:00
ruff_graph Bump MSRV to Rust 1.80 (#13826) 2024-10-20 10:55:36 +02:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter Also remove trailing comma while fixing C409 and C419 (#14097) 2024-11-04 20:33:30 +00:00
ruff_macros Derive message formats macro support to string (#14093) 2024-11-04 18:06:25 +01:00
ruff_notebook Bump MSRV to Rust 1.80 (#13826) 2024-10-20 10:55:36 +02:00
ruff_python_ast Avoid cloning Name when looking up function and class types (#14092) 2024-11-04 15:52:59 +01:00
ruff_python_ast_integration_tests [internal] ComparableExpr (f)strings and bytes made invariant under concatenation (#13301) 2024-09-25 16:58:57 +02:00
ruff_python_codegen Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_formatter Disallow single-line implicit concatenated strings (#13928) 2024-11-03 11:49:26 +00:00
ruff_python_index Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_literal Remove some unused pub functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Short circuit lex_identifier if the name is longer or shorter than any known keyword (#13815) 2024-10-19 11:07:15 +00:00
ruff_python_resolver chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
ruff_python_semantic Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_stdlib Regenerate known_stdlibs.rs with stdlibs 2024.10.25 (#13963) 2024-10-28 08:37:54 -04:00
ruff_python_trivia Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_python_trivia_integration_tests Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_server Fix server panic when undoing an edit (#14010) 2024-11-01 08:16:53 +01:00
ruff_source_file Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_text_size Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
ruff_wasm Bump version to 0.7.2 (#14039) 2024-11-01 19:09:07 +05:30
ruff_workspace Enable nursery rules: 'redundant_clone', 'debug_assert_with_mut_call', and 'unused_peekable' (#13920) 2024-10-25 09:46:30 +02:00