mirror of https://github.com/astral-sh/ruff
[ty] Remove `Self` from generic context when binding `Self`
This commit is contained in:
parent
65982a1e14
commit
b1e64a0da4
|
|
@ -17,8 +17,8 @@ use crate::types::tuple::{TupleSpec, TupleType, walk_tuple_type};
|
|||
use crate::types::{
|
||||
ApplyTypeMappingVisitor, BoundTypeVarInstance, FindLegacyTypeVarsVisitor, HasRelationToVisitor,
|
||||
IsEquivalentVisitor, KnownClass, KnownInstanceType, MaterializationKind, NormalizedVisitor,
|
||||
Type, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarVariance,
|
||||
UnionType, binding_type, declaration_type,
|
||||
Type, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind,
|
||||
TypeVarVariance, UnionType, binding_type, declaration_type,
|
||||
};
|
||||
use crate::{Db, FxOrderSet};
|
||||
|
||||
|
|
@ -401,6 +401,17 @@ impl<'db> GenericContext<'db> {
|
|||
fn heap_size((variables,): &(FxOrderSet<BoundTypeVarInstance<'db>>,)) -> usize {
|
||||
ruff_memory_usage::order_set_heap_size(variables)
|
||||
}
|
||||
|
||||
/// Returns a version of this generic context with the `Self` typevar removed.
|
||||
pub(crate) fn bind_self(self, db: &'db dyn Db) -> Self {
|
||||
Self::from_typevar_instances(
|
||||
db,
|
||||
self.variables(db)
|
||||
.iter()
|
||||
.filter(|typevar| typevar.typevar(db).kind(db) != TypeVarKind::TypingSelf)
|
||||
.copied(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -522,7 +522,7 @@ impl<'db> Signature<'db> {
|
|||
return_ty.map(|ty| ty.apply_type_mapping(db, &TypeMapping::BindSelf(self_type)));
|
||||
}
|
||||
Self {
|
||||
generic_context: self.generic_context,
|
||||
generic_context: self.generic_context.map(|context| context.bind_self(db)),
|
||||
inherited_generic_context: self.inherited_generic_context,
|
||||
definition: self.definition,
|
||||
parameters,
|
||||
|
|
|
|||
Loading…
Reference in New Issue