mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Add precise inference for unpacking a TypeVar if the TypeVar has an upper bound with a precise tuple spec (#19985)
This commit is contained in:
parent
c82e255ca8
commit
662d18bd05
3 changed files with 94 additions and 2 deletions
|
@ -4870,6 +4870,18 @@ impl<'db> Type<'db> {
|
|||
Type::TypeAlias(alias) => {
|
||||
return alias.value_type(db).try_iterate_with_mode(db, mode);
|
||||
}
|
||||
Type::NonInferableTypeVar(tvar) => match tvar.typevar(db).bound_or_constraints(db) {
|
||||
Some(TypeVarBoundOrConstraints::UpperBound(bound)) => {
|
||||
return bound.try_iterate_with_mode(db, mode);
|
||||
}
|
||||
// TODO: could we create a "union of tuple specs"...?
|
||||
// (Same question applies to the `Type::Union()` branch lower down)
|
||||
Some(TypeVarBoundOrConstraints::Constraints(_)) | None => {}
|
||||
},
|
||||
Type::TypeVar(_) => unreachable!(
|
||||
"should not be able to iterate over type variable {} in inferable position",
|
||||
self.display(db)
|
||||
),
|
||||
Type::Dynamic(_)
|
||||
| Type::FunctionLiteral(_)
|
||||
| Type::GenericAlias(_)
|
||||
|
@ -4895,8 +4907,6 @@ impl<'db> Type<'db> {
|
|||
| Type::EnumLiteral(_)
|
||||
| Type::LiteralString
|
||||
| Type::BytesLiteral(_)
|
||||
| Type::TypeVar(_)
|
||||
| Type::NonInferableTypeVar(_)
|
||||
| Type::BoundSuper(_)
|
||||
| Type::TypeIs(_)
|
||||
| Type::TypedDict(_) => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue