ruff/crates
David Peter 6964eef369
[red knot] add Type::is_disjoint_from and intersection simplifications (#13775)
## Summary

- Add `Type::is_disjoint_from` as a way to test whether two types
overlap
- Add a first set of simplification rules for intersection types
  - `S & T = S` for `S <: T`
  - `S & ~T = Never` for `S <: T`
  - `~S & ~T = ~T` for `S <: T`
  - `A & ~B = A` for `A` disjoint from `B`
  - `A & B = Never` for `A` disjoint from `B`
  - `bool & ~Literal[bool] = Literal[!bool]`

resolves one item in #12694

## Open questions:

- Can we somehow leverage the (anti) symmetry between `positive` and
`negative` contributions? I could imagine that there would be a way if
we had `Type::Not(type)`/`Type::Negative(type)`, but with the
`positive`/`negative` architecture, I'm not sure. Note that there is a
certain duplication in the `add_positive`/`add_negative` functions (e.g.
`S & ~T = Never` is implemented twice), but other rules are actually not
perfectly symmetric: `S & T = S` vs `~S & ~T = ~T`.
- I'm not particularly proud of the way `add_positive`/`add_negative`
turned out. They are long imperative-style functions with some
mutability mixed in (`to_remove`). I'm happy to look into ways to
improve this code *if we decide to go with this approach* of
implementing a set of ad-hoc rules for simplification.
- ~~Is it useful to perform simplifications eagerly in
`add_positive`/`add_negative`? (@carljm)~~ This is what I did for now.

## Test Plan

- Unit tests for `Type::is_disjoint_from`
- Observe changes in Markdown-based tests
- Unit tests for `IntersectionBuilder::build()`

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2024-10-18 21:34:43 +00:00
..
red_knot Upgrade salsa (#13757) 2024-10-15 11:06:32 +00:00
red_knot_python_semantic [red knot] add Type::is_disjoint_from and intersection simplifications (#13775) 2024-10-18 21:34:43 +00:00
red_knot_server Revert "Upgrade to Rust 1.82 toolchain" (#13810) 2024-10-18 12:18:26 +00:00
red_knot_test [red-knot] Port type inference tests to new test framework (#13719) 2024-10-15 11:23:46 -07:00
red_knot_vendored Sync vendored typeshed stubs (#13753) 2024-10-15 13:36:11 +00:00
red_knot_wasm Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_workspace [red-knot] Infer target types for unpacked tuple assignment (#13316) 2024-10-15 19:07:11 +00:00
ruff Changelog for Ruff v0.7 (#13794) 2024-10-17 16:14:21 +00:00
ruff_benchmark [red-knot] Add control flow for try/except blocks (#13729) 2024-10-16 13:03:59 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_dev Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_diagnostics [Minor typo] Fix article in "an fix" (#12797) 2024-08-10 21:22:00 -04:00
ruff_formatter Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_graph Upgrade salsa (#13757) 2024-10-15 11:06:32 +00: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 Revert "Upgrade to Rust 1.82 toolchain" (#13810) 2024-10-18 12:18:26 +00:00
ruff_macros Revert "Upgrade to Rust 1.82 toolchain" (#13810) 2024-10-18 12:18:26 +00:00
ruff_notebook Allow ipytest cell magic (#13745) 2024-10-14 15:48:33 +05:30
ruff_python_ast Refactor: Remove StringPart and AnyStringPart in favor of StringLikePart (#13772) 2024-10-16 12:52:06 +02: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 Implement iter(), len() and is_empty() for all display-literal AST nodes (#12807) 2024-08-12 10:39:28 +00:00
ruff_python_formatter Revert "Upgrade to Rust 1.82 toolchain" (#13810) 2024-10-18 12:18:26 +00:00
ruff_python_index Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
ruff_python_literal Remove some unused pub functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Expose internal types as public access (#13509) 2024-09-26 17:34:30 +02: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 Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_stdlib Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_trivia [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_python_trivia_integration_tests Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_server Revert "Upgrade to Rust 1.82 toolchain" (#13810) 2024-10-18 12:18:26 +00:00
ruff_source_file Fix off-by one error in the LineIndex::offset calculation (#13407) 2024-09-19 11:58:45 +00:00
ruff_text_size [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_wasm Changelog for Ruff v0.7 (#13794) 2024-10-17 16:14:21 +00:00
ruff_workspace Remove allow-unused-imports setting from the common lint options (#13677) 2024-10-17 16:35:12 +01:00