[ty] Simplify union lower bounds and intersection upper bounds in constraint sets by dcreager · Pull Request #21871 · astral-sh/ruff (original) (raw)
An internal refactor or improvement
Multi-file analysis & type inference
labels
dcreager deleted the dcreager/die-die-intersections branch
dcreager added a commit that referenced this pull request
- origin/main: (33 commits)
[ty] Simplify union lower bounds and intersection upper bounds in constraint sets (#21871)
[ty] Collapse
neverpaths in constraint set BDDs (#21880) Fix leading comment formatting for lambdas with multiple parameters (#21879) [ty] Type inference for@asynccontextmanager(#21876) Fix comment placement in lambda parameters (#21868) [pylint] Detect subclasses of builtin exceptions (PLW0133) (#21382) Fix stack overflow with recursive generic protocols (depth limit) (#21858) New diagnostics for unused range suppressions (#21783) [ty] Use default settings in completion tests [ty] Infer type variables within generic unions (#21862) [ty] Fix overload filtering to prefer more "precise" match (#21859) [ty] Stabilize auto-import [ty] Fix reveal-type E2E test (#21865) [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850) Include more details in Tokens 'offset is inside token' panic message (#21860) apply range suppressions to filter diagnostics (#21623) [ty] followup: add-import action forreveal_typetoo (#21668) [ty] Enrich function argument auto-complete suggestions with annotated types [ty] Add autocomplete suggestions for function arguments [flake8-bugbear] Accept immutable slice default arguments (B008) (#21823) ...
dcreager added a commit that referenced this pull request
This fixes the logic error that @sharkdp [found](#21871 (comment)) in the constraint set upper bound normalization logic I introduced in #21871.
I had originally claimed that (T ≤ α & ~β) should simplify into (T ≤ α) ∧ ¬(T ≤ β). But that also suggests that T ≤ ~β should simplify to
¬(T ≤ β) on its own, and that's not correct.
The correct simplification is that ~α is an "atomic" type, not an
"intersection" for the purposes of our upper bound simplifcation. So (T ≤ α & ~β) should simplify to (T ≤ α) ∧ (T ≤ ~β). That is, break apart
the elements of a (proper) intersection, regardless of whether each
element is negated or not.
This PR fixes the logic, adds a test case, and updates the comments to be hopefully more clear and accurate.
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request
This fixes the logic error that @sharkdp [found](astral-sh/ruff#21871 (comment)) in the constraint set upper bound normalization logic I introduced in #21871.
I had originally claimed that (T ≤ α & ~β) should simplify into (T ≤ α) ∧ ¬(T ≤ β). But that also suggests that T ≤ ~β should simplify to
¬(T ≤ β) on its own, and that's not correct.
The correct simplification is that ~α is an "atomic" type, not an
"intersection" for the purposes of our upper bound simplifcation. So (T ≤ α & ~β) should simplify to (T ≤ α) ∧ (T ≤ ~β). That is, break apart
the elements of a (proper) intersection, regardless of whether each
element is negated or not.
This PR fixes the logic, adds a test case, and updates the comments to be hopefully more clear and accurate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})