Skip to content

Commit db08069

Browse files
committed
fix incorrect branch
1 parent 0db080d commit db08069

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

crates/red_knot_python_semantic/src/stdlib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(crate) enum CoreStdlibModule {
1515
TypingExtensions,
1616
Typing,
1717
Sys,
18+
#[allow(dead_code)]
19+
Abc, // currently only used in tests
1820
}
1921

2022
impl CoreStdlibModule {
@@ -26,6 +28,7 @@ impl CoreStdlibModule {
2628
Self::Typeshed => "_typeshed",
2729
Self::TypingExtensions => "typing_extensions",
2830
Self::Sys => "sys",
31+
Self::Abc => "abc",
2932
}
3033
}
3134

crates/red_knot_python_semantic/src/types.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,12 @@ impl<'db> Type<'db> {
661661
}),
662662
) => self_class.is_subclass_of(db, target_class),
663663
(
664-
Type::Instance(InstanceType { class: self_class }),
664+
Type::Instance(_),
665665
Type::SubclassOf(SubclassOfType {
666666
base: ClassBase::Class(target_class),
667667
}),
668-
) => {
669-
self_class.is_known(db, KnownClass::Type)
670-
&& target_class.is_known(db, KnownClass::Type)
668+
) if target_class.is_known(db, KnownClass::Object) => {
669+
self.is_subtype_of(db, KnownClass::Type.to_instance(db))
671670
}
672671
(
673672
Type::SubclassOf(SubclassOfType {
@@ -3046,12 +3045,18 @@ pub(crate) mod tests {
30463045
// BuiltinInstance("str") corresponds to an instance of the builtin `str` class
30473046
BuiltinInstance(&'static str),
30483047
TypingInstance(&'static str),
3048+
/// Members of the `abc` stdlib module
3049+
AbcInstance(&'static str),
3050+
AbcClassLiteral(&'static str),
30493051
TypingLiteral,
30503052
// BuiltinClassLiteral("str") corresponds to the builtin `str` class object itself
30513053
BuiltinClassLiteral(&'static str),
30523054
KnownClassInstance(KnownClass),
30533055
Union(Vec<Ty>),
3054-
Intersection { pos: Vec<Ty>, neg: Vec<Ty> },
3056+
Intersection {
3057+
pos: Vec<Ty>,
3058+
neg: Vec<Ty>,
3059+
},
30553060
Tuple(Vec<Ty>),
30563061
SubclassOfAny,
30573062
SubclassOfBuiltinClass(&'static str),
@@ -3071,6 +3076,12 @@ pub(crate) mod tests {
30713076
Ty::LiteralString => Type::LiteralString,
30723077
Ty::BytesLiteral(s) => Type::bytes_literal(db, s.as_bytes()),
30733078
Ty::BuiltinInstance(s) => builtins_symbol(db, s).expect_type().to_instance(db),
3079+
Ty::AbcInstance(s) => core_module_symbol(db, CoreStdlibModule::Abc, s)
3080+
.expect_type()
3081+
.to_instance(db),
3082+
Ty::AbcClassLiteral(s) => {
3083+
core_module_symbol(db, CoreStdlibModule::Abc, s).expect_type()
3084+
}
30743085
Ty::TypingInstance(s) => typing_symbol(db, s).expect_type().to_instance(db),
30753086
Ty::TypingLiteral => Type::KnownInstance(KnownInstanceType::Literal),
30763087
Ty::BuiltinClassLiteral(s) => builtins_symbol(db, s).expect_type(),
@@ -3223,6 +3234,8 @@ pub(crate) mod tests {
32233234
#[test_case(Ty::BuiltinClassLiteral("int"), Ty::BuiltinInstance("object"))]
32243235
#[test_case(Ty::TypingLiteral, Ty::TypingInstance("_SpecialForm"))]
32253236
#[test_case(Ty::TypingLiteral, Ty::BuiltinInstance("object"))]
3237+
#[test_case(Ty::AbcClassLiteral("ABC"), Ty::AbcInstance("ABCMeta"))]
3238+
#[test_case(Ty::AbcInstance("ABCMeta"), Ty::SubclassOfBuiltinClass("object"))]
32263239
fn is_subtype_of(from: Ty, to: Ty) {
32273240
let db = setup_db();
32283241
assert!(from.into_type(&db).is_subtype_of(&db, to.into_type(&db)));
@@ -3255,6 +3268,7 @@ pub(crate) mod tests {
32553268
#[test_case(Ty::TypingInstance("_SpecialForm"), Ty::TypingLiteral)]
32563269
#[test_case(Ty::BuiltinInstance("type"), Ty::SubclassOfBuiltinClass("str"))]
32573270
#[test_case(Ty::BuiltinClassLiteral("str"), Ty::SubclassOfAny)]
3271+
#[test_case(Ty::AbcInstance("ABCMeta"), Ty::SubclassOfBuiltinClass("type"))]
32583272
fn is_not_subtype_of(from: Ty, to: Ty) {
32593273
let db = setup_db();
32603274
assert!(!from.into_type(&db).is_subtype_of(&db, to.into_type(&db)));

0 commit comments

Comments
 (0)