mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
Rename get_self_type, cleanup
This commit is contained in:
parent
40ffa0c6da
commit
0b99dfdb90
3 changed files with 8 additions and 7 deletions
|
@ -52,7 +52,7 @@ use crate::types::function::{
|
|||
DataclassTransformerParams, FunctionSpans, FunctionType, KnownFunction,
|
||||
};
|
||||
use crate::types::generics::{
|
||||
GenericContext, PartialSpecialization, Specialization, bind_typevar, get_self_type,
|
||||
GenericContext, PartialSpecialization, Specialization, bind_typevar, typing_self,
|
||||
walk_generic_context, walk_partial_specialization, walk_specialization,
|
||||
};
|
||||
pub use crate::types::ide_support::{
|
||||
|
@ -5710,7 +5710,7 @@ impl<'db> Type<'db> {
|
|||
],
|
||||
});
|
||||
};
|
||||
let self_type = get_self_type(db, scope_id, typevar_binding_context, class);
|
||||
let self_type = typing_self(db, scope_id, typevar_binding_context, class);
|
||||
Ok(self_type.map(Type::NonInferableTypeVar).unwrap_or(*self))
|
||||
}
|
||||
SpecialFormType::TypeAlias => Ok(Type::Dynamic(DynamicType::TodoTypeAlias)),
|
||||
|
|
|
@ -103,7 +103,8 @@ pub(crate) fn bind_typevar<'db>(
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_self_type<'db>(
|
||||
/// Create a `typing.Self` type variable for a given class.
|
||||
pub(crate) fn typing_self<'db>(
|
||||
db: &'db dyn Db,
|
||||
scope_id: ScopeId,
|
||||
typevar_binding_context: Option<Definition<'db>>,
|
||||
|
@ -112,11 +113,10 @@ pub(crate) fn get_self_type<'db>(
|
|||
let module = parsed_module(db, scope_id.file(db)).load(db);
|
||||
let index = semantic_index(db, scope_id.file(db));
|
||||
|
||||
let class_definition = class.definition(db);
|
||||
let typevar = TypeVarInstance::new(
|
||||
db,
|
||||
ast::name::Name::new_static("Self"),
|
||||
Some(class_definition),
|
||||
Some(class.definition(db)),
|
||||
Some(
|
||||
TypeVarBoundOrConstraints::UpperBound(Type::instance(
|
||||
db,
|
||||
|
@ -131,6 +131,7 @@ pub(crate) fn get_self_type<'db>(
|
|||
None,
|
||||
TypeVarKind::TypingSelf,
|
||||
);
|
||||
|
||||
bind_typevar(
|
||||
db,
|
||||
&module,
|
||||
|
|
|
@ -22,7 +22,7 @@ use super::{
|
|||
use crate::semantic_index::definition::Definition;
|
||||
use crate::types::constraints::{ConstraintSet, IteratorConstraintsExtension};
|
||||
use crate::types::function::FunctionType;
|
||||
use crate::types::generics::{GenericContext, get_self_type, walk_generic_context};
|
||||
use crate::types::generics::{GenericContext, typing_self, walk_generic_context};
|
||||
use crate::types::infer::nearest_enclosing_class;
|
||||
use crate::types::{
|
||||
ApplyTypeMappingVisitor, BindingContext, BoundTypeVarInstance, ClassType,
|
||||
|
@ -1296,7 +1296,7 @@ impl<'db> Parameters<'db> {
|
|||
let index = semantic_index(db, scope_id.file(db));
|
||||
let class = nearest_enclosing_class(db, index, scope_id).unwrap();
|
||||
Type::NonInferableTypeVar(
|
||||
get_self_type(db, scope_id, typevar_binding_context, class).unwrap(),
|
||||
typing_self(db, scope_id, typevar_binding_context, class).unwrap(),
|
||||
)
|
||||
.apply_type_mapping(
|
||||
db,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue