[ty] Allow tuple[Any, ...] to assign to tuple[int, *tuple[int, ...]] (#21803)
Some checks failed
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (${{ github.repository == 'astral-sh/ruff' && 'depot-windows-2022-16' || 'windows-latest' }}) (push) Blocked by required conditions
CI / cargo test (macos-latest) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / ty completion evaluation (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks walltime (medium|multithreaded) (push) Blocked by required conditions
CI / benchmarks walltime (small|large) (push) Blocked by required conditions
[ty Playground] Release / publish (push) Has been cancelled

## Summary

Closes https://github.com/astral-sh/ty/issues/1750.
This commit is contained in:
Charlie Marsh 2025-12-05 11:04:23 -08:00 committed by GitHub
parent 9714c589e1
commit ef45c97dab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 6 deletions

View file

@ -998,10 +998,22 @@ impl<'db> VariableLengthTuple<Type<'db>> {
relation_visitor,
disjointness_visitor,
),
EitherOrBoth::Right(_) => {
EitherOrBoth::Right(other_ty) => {
// The rhs has a required element that the lhs is not guaranteed to
// provide.
return ConstraintSet::from(false);
// provide, unless the lhs has a dynamic variable-length portion
// that can materialize to provide it (for assignability only),
// as in `tuple[Any, ...]` matching `tuple[int, int]`.
if !relation.is_assignability() || !self.variable.is_dynamic() {
return ConstraintSet::from(false);
}
self.variable.has_relation_to_impl(
db,
other_ty,
inferable,
relation,
relation_visitor,
disjointness_visitor,
)
}
};
if result
@ -1037,10 +1049,22 @@ impl<'db> VariableLengthTuple<Type<'db>> {
relation_visitor,
disjointness_visitor,
),
EitherOrBoth::Right(_) => {
EitherOrBoth::Right(other_ty) => {
// The rhs has a required element that the lhs is not guaranteed to
// provide.
return ConstraintSet::from(false);
// provide, unless the lhs has a dynamic variable-length portion
// that can materialize to provide it (for assignability only),
// as in `tuple[Any, ...]` matching `tuple[int, int]`.
if !relation.is_assignability() || !self.variable.is_dynamic() {
return ConstraintSet::from(false);
}
self.variable.has_relation_to_impl(
db,
*other_ty,
inferable,
relation,
relation_visitor,
disjointness_visitor,
)
}
};
if result