mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-22 21:25:27 +00:00
todo class bases
This commit is contained in:
parent
1fee6c3ede
commit
ecda934c36
2 changed files with 20 additions and 17 deletions
|
|
@ -38,7 +38,7 @@ use crate::types::{
|
||||||
ManualPEP695TypeAliasType, MaterializationKind, NormalizedVisitor, PropertyInstanceType,
|
ManualPEP695TypeAliasType, MaterializationKind, NormalizedVisitor, PropertyInstanceType,
|
||||||
StringLiteralType, TypeAliasType, TypeContext, TypeMapping, TypeRelation, TypedDictParams,
|
StringLiteralType, TypeAliasType, TypeContext, TypeMapping, TypeRelation, TypedDictParams,
|
||||||
UnionBuilder, VarianceInferable, declaration_type, determine_upper_bound,
|
UnionBuilder, VarianceInferable, declaration_type, determine_upper_bound,
|
||||||
exceeds_max_specialization_depth, infer_definition_types,
|
exceeds_max_specialization_depth, infer_definition_types, todo_type,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
Db, FxIndexMap, FxIndexSet, FxOrderSet, Program,
|
Db, FxIndexMap, FxIndexSet, FxOrderSet, Program,
|
||||||
|
|
@ -1598,7 +1598,12 @@ impl<'db> ClassLiteral<'db> {
|
||||||
let class_definition =
|
let class_definition =
|
||||||
semantic_index(db, self.file(db)).expect_single_definition(class_stmt);
|
semantic_index(db, self.file(db)).expect_single_definition(class_stmt);
|
||||||
|
|
||||||
if self.is_known(db, KnownClass::VersionInfo) {
|
if class_stmt.bases().iter().any(ast::Expr::is_starred_expr) {
|
||||||
|
return Box::new([todo_type!("Starred expressions in class bases")]);
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.known(db) {
|
||||||
|
Some(KnownClass::VersionInfo) => {
|
||||||
let tuple_type = TupleType::new(db, &TupleSpec::version_info_spec(db))
|
let tuple_type = TupleType::new(db, &TupleSpec::version_info_spec(db))
|
||||||
.expect("sys.version_info tuple spec should always be a valid tuple");
|
.expect("sys.version_info tuple spec should always be a valid tuple");
|
||||||
|
|
||||||
|
|
@ -1606,12 +1611,15 @@ impl<'db> ClassLiteral<'db> {
|
||||||
definition_expression_type(db, class_definition, &class_stmt.bases()[0]),
|
definition_expression_type(db, class_definition, &class_stmt.bases()[0]),
|
||||||
Type::from(tuple_type.to_class_type(db)),
|
Type::from(tuple_type.to_class_type(db)),
|
||||||
])
|
])
|
||||||
} else {
|
}
|
||||||
class_stmt
|
// Special-case `NotImplementedType`: typeshed says that it inherits from `Any`,
|
||||||
|
// but this causes more problems than it fixes.
|
||||||
|
Some(KnownClass::NotImplementedType) => Box::new([]),
|
||||||
|
_ => class_stmt
|
||||||
.bases()
|
.bases()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|base_node| definition_expression_type(db, class_definition, base_node))
|
.map(|base_node| definition_expression_type(db, class_definition, base_node))
|
||||||
.collect()
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use rustc_hash::FxBuildHasher;
|
||||||
use crate::Db;
|
use crate::Db;
|
||||||
use crate::types::class_base::ClassBase;
|
use crate::types::class_base::ClassBase;
|
||||||
use crate::types::generics::Specialization;
|
use crate::types::generics::Specialization;
|
||||||
use crate::types::{ClassLiteral, ClassType, KnownClass, KnownInstanceType, SpecialFormType, Type};
|
use crate::types::{ClassLiteral, ClassType, KnownInstanceType, SpecialFormType, Type};
|
||||||
|
|
||||||
/// The inferred method resolution order of a given class.
|
/// The inferred method resolution order of a given class.
|
||||||
///
|
///
|
||||||
|
|
@ -52,11 +52,6 @@ impl<'db> Mro<'db> {
|
||||||
specialization: Option<Specialization<'db>>,
|
specialization: Option<Specialization<'db>>,
|
||||||
) -> Result<Self, MroError<'db>> {
|
) -> Result<Self, MroError<'db>> {
|
||||||
let class = class_literal.apply_optional_specialization(db, specialization);
|
let class = class_literal.apply_optional_specialization(db, specialization);
|
||||||
// Special-case `NotImplementedType`: typeshed says that it inherits from `Any`,
|
|
||||||
// but this causes more problems than it fixes.
|
|
||||||
if class_literal.is_known(db, KnownClass::NotImplementedType) {
|
|
||||||
return Ok(Self::from([ClassBase::Class(class), ClassBase::object(db)]));
|
|
||||||
}
|
|
||||||
Self::of_class_impl(db, class, class_literal.explicit_bases(db), specialization)
|
Self::of_class_impl(db, class, class_literal.explicit_bases(db), specialization)
|
||||||
.map_err(|err| err.into_mro_error(db, class))
|
.map_err(|err| err.into_mro_error(db, class))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue