Visitar URL original
[ty] Constraining a typevar with itself (possibly via union or intersection) by dcreager · Pull Request #21273 · astral-sh/ruff · GitHub
Skip to content

[ty] Constraining a typevar with itself (possibly via union or intersection) - #21273

Merged
dcreager merged 3 commits into
mainfrom
dcreager/union-intersection
Nov 5, 2025
Merged

dcreager merged 3 commits into
mainfrom
dcreager/union-intersection

Conversation

@dcreager

@dcreager dcreager commented Nov 4, 2025

Copy link
Copy Markdown
Member

This PR carries over some of the has_relation_to logic for comparing a typevar with itself. A typevar will specialize to the same type if it's mentioned multiple times, so it is always assignable to and a subtype of itself. (Note that typevars can only specialize to fully static types.) This is also true when the typevar appears in a union on the right-hand side, or in an intersection on the left-hand side. Similarly, a typevar is always disjoint from its negation, so when a negated typevar appears on the left-hand side, the constraint set is never satisfiable.

(Eventually this will allow us to remove the corresponding clauses from has_relation_to, but that can't happen until more of #20093 lands.)

@dcreager dcreager added internal An internal refactor or improvement (not for changelogs) ty The ty type checker labels Nov 4, 2025
@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@dcreager
dcreager merged commit eda85f3 into main Nov 5, 2025
@dcreager
dcreager deleted the dcreager/union-intersection branch November 5, 2025 17:31
carljm added a commit to MatthewMckee4/ruff that referenced this pull request Nov 6, 2025
* main: (188 commits)
  [ty] Discover site-packages from the environment that ty is installed in (astral-sh#21286)
  [ty] Make special cases for `UnionType` slightly narrower (astral-sh#21276)
  Require ignore 0.4.24 in `Cargo.toml` (astral-sh#21292)
  [ty] Favour imported symbols over builtin symbols (astral-sh#21285)
  docs: revise Ruff setup instructions for Zed editor (astral-sh#20935)
  [ty] Update salsa (astral-sh#21281)
  [syntax-error]: no binding for nonlocal  PLE0117 as a semantic syntax error (astral-sh#21032)
  [ty] Constraining a typevar with itself (possibly via union or intersection) (astral-sh#21273)
  [`ruff`] Fix false positives on starred arguments (`RUF057`) (astral-sh#21256)
  [ty] Simplify unions containing multiple type variables during inference (astral-sh#21275)
  [ty] Add `ty_server::Db` trait (astral-sh#21241)
  [ty] Refactor `Range` to/from `TextRange` conversion as prep for notebook support (astral-sh#21230)
  [ty] Fix playground crash when file name includes path separator (astral-sh#21151)
  [`refurb`] Fix false negative for underscores before sign in `Decimal` constructor (`FURB157`) (astral-sh#21190)
  [ty] Allow values of type `None` in type expressions (astral-sh#21263)
  Run codspeed benchmarks with `profiling` profile (astral-sh#21261)
  [ty] Update expected diagnostic count in benchmarks (astral-sh#21269)
  Avoid extra parentheses for long `match` patterns with `as` captures (astral-sh#21176)
  [ty] Update salsa (astral-sh#21265)
  [ty] `dict` is not assignable to `TypedDict` (astral-sh#21238)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement (not for changelogs) ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants