Skip to content

Commit 16721b3

Browse files
committed
todo class bases
1 parent 93e6023 commit 16721b3

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

crates/ty_python_semantic/src/types/class.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::types::{
3838
ManualPEP695TypeAliasType, MaterializationKind, NormalizedVisitor, PropertyInstanceType,
3939
StringLiteralType, TypeAliasType, TypeContext, TypeMapping, TypeRelation, TypedDictParams,
4040
UnionBuilder, VarianceInferable, binding_type, declaration_type, determine_upper_bound,
41+
todo_type,
4142
};
4243
use crate::{
4344
Db, FxIndexMap, FxIndexSet, FxOrderSet, Program,
@@ -1664,20 +1665,28 @@ impl<'db> ClassLiteral<'db> {
16641665
let class_definition =
16651666
semantic_index(db, self.file(db)).expect_single_definition(class_stmt);
16661667

1667-
if self.is_known(db, KnownClass::VersionInfo) {
1668-
let tuple_type = TupleType::new(db, &TupleSpec::version_info_spec(db))
1669-
.expect("sys.version_info tuple spec should always be a valid tuple");
1668+
if class_stmt.bases().iter().any(ast::Expr::is_starred_expr) {
1669+
return Box::new([todo_type!("Starred expressions in class bases")]);
1670+
}
16701671

1671-
Box::new([
1672-
definition_expression_type(db, class_definition, &class_stmt.bases()[0]),
1673-
Type::from(tuple_type.to_class_type(db)),
1674-
])
1675-
} else {
1676-
class_stmt
1672+
match self.known(db) {
1673+
Some(KnownClass::VersionInfo) => {
1674+
let tuple_type = TupleType::new(db, &TupleSpec::version_info_spec(db))
1675+
.expect("sys.version_info tuple spec should always be a valid tuple");
1676+
1677+
Box::new([
1678+
definition_expression_type(db, class_definition, &class_stmt.bases()[0]),
1679+
Type::from(tuple_type.to_class_type(db)),
1680+
])
1681+
}
1682+
// Special-case `NotImplementedType`: typeshed says that it inherits from `Any`,
1683+
// but this causes more problems than it fixes.
1684+
Some(KnownClass::NotImplementedType) => Box::new([]),
1685+
_ => class_stmt
16771686
.bases()
16781687
.iter()
16791688
.map(|base_node| definition_expression_type(db, class_definition, base_node))
1680-
.collect()
1689+
.collect(),
16811690
}
16821691
}
16831692

crates/ty_python_semantic/src/types/mro.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hash::FxBuildHasher;
77
use crate::Db;
88
use crate::types::class_base::ClassBase;
99
use crate::types::generics::Specialization;
10-
use crate::types::{ClassLiteral, ClassType, KnownClass, KnownInstanceType, SpecialFormType, Type};
10+
use crate::types::{ClassLiteral, ClassType, KnownInstanceType, SpecialFormType, Type};
1111

1212
/// The inferred method resolution order of a given class.
1313
///
@@ -52,11 +52,6 @@ impl<'db> Mro<'db> {
5252
specialization: Option<Specialization<'db>>,
5353
) -> Result<Self, MroError<'db>> {
5454
let class = class_literal.apply_optional_specialization(db, specialization);
55-
// Special-case `NotImplementedType`: typeshed says that it inherits from `Any`,
56-
// but this causes more problems than it fixes.
57-
if class_literal.is_known(db, KnownClass::NotImplementedType) {
58-
return Ok(Self::from([ClassBase::Class(class), ClassBase::object(db)]));
59-
}
6055
Self::of_class_impl(db, class, class_literal.explicit_bases(db), specialization)
6156
.map_err(|err| err.into_mro_error(db, class))
6257
}

0 commit comments

Comments
 (0)