Skip to content

Commit 7408664

Browse files
committed
Add TypeMapping::update_signature_generic_context
1 parent 9649de7 commit 7408664

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6768,6 +6768,37 @@ impl<'db> TypeMapping<'_, 'db> {
67686768
}
67696769
}
67706770
}
6771+
6772+
/// Update the generic context of a [`Signature`] according to the current type mapping
6773+
pub(crate) fn update_signature_generic_context(
6774+
&self,
6775+
db: &'db dyn Db,
6776+
context: GenericContext<'db>,
6777+
) -> GenericContext<'db> {
6778+
match self {
6779+
TypeMapping::Specialization(_)
6780+
| TypeMapping::PartialSpecialization(_)
6781+
| TypeMapping::PromoteLiterals
6782+
| TypeMapping::BindLegacyTypevars(_)
6783+
| TypeMapping::MarkTypeVarsInferable(_)
6784+
| TypeMapping::Materialize(_)
6785+
| TypeMapping::BindSelf(_) => context,
6786+
TypeMapping::ReplaceSelf { new_upper_bound } => GenericContext::from_typevar_instances(
6787+
db,
6788+
context.variables(db).iter().map(|typevar| {
6789+
if typevar.typevar(db).is_self(db) {
6790+
BoundTypeVarInstance::synthetic_self(
6791+
db,
6792+
*new_upper_bound,
6793+
typevar.binding_context(db),
6794+
)
6795+
} else {
6796+
*typevar
6797+
}
6798+
}),
6799+
),
6800+
}
6801+
}
67716802
}
67726803

67736804
/// A Salsa-tracked constraint set. This is only needed to have something appropriately small to

crates/ty_python_semantic/src/types/signatures.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -470,26 +470,9 @@ impl<'db> Signature<'db> {
470470
_ => type_mapping,
471471
};
472472
Self {
473-
generic_context: if let TypeMapping::ReplaceSelf { new_upper_bound } = type_mapping {
474-
self.generic_context.map(|context| {
475-
GenericContext::from_typevar_instances(
476-
db,
477-
context.variables(db).iter().map(|typevar| {
478-
if typevar.typevar(db).is_self(db) {
479-
BoundTypeVarInstance::synthetic_self(
480-
db,
481-
*new_upper_bound,
482-
typevar.binding_context(db),
483-
)
484-
} else {
485-
*typevar
486-
}
487-
}),
488-
)
489-
})
490-
} else {
491-
self.generic_context
492-
},
473+
generic_context: self
474+
.generic_context
475+
.map(|context| type_mapping.update_signature_generic_context(db, context)),
493476
inherited_generic_context: self.inherited_generic_context,
494477
definition: self.definition,
495478
parameters: self

0 commit comments

Comments
 (0)