Skip to content

Commit

Permalink
Fix instance checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Oct 17, 2024
1 parent efe64d8 commit 215ef0c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ impl<'db> Type<'db> {
| Type::LiteralString
| Type::BytesLiteral(..) => true,
Type::None => false,
Type::Instance(class_type) => !class_type.is_known(db, KnownClass::NoneType),
Type::Instance(class_type) => {
!class_type.is_known(db, KnownClass::NoneType)
&& !class_type.is_known(db, KnownClass::Object)
}
},

(Type::BooleanLiteral(bool), other) | (other, Type::BooleanLiteral(bool)) => {
Expand All @@ -569,7 +572,10 @@ impl<'db> Type<'db> {
| Type::LiteralString
| Type::BytesLiteral(..) => true,
Type::BooleanLiteral(bool_other) => bool != bool_other,
Type::Instance(class_type) => !class_type.is_known(db, KnownClass::Bool),
Type::Instance(class_type) => {
!class_type.is_known(db, KnownClass::Bool)
&& !class_type.is_known(db, KnownClass::Object)
}
}
}

Expand All @@ -591,7 +597,10 @@ impl<'db> Type<'db> {
}
Type::StringLiteral(..) | Type::LiteralString | Type::BytesLiteral(..) => true,
Type::IntLiteral(int_other) => int != int_other,
Type::Instance(..) => false,
Type::Instance(class_type) => {
!class_type.is_known(db, KnownClass::Int)
&& !class_type.is_known(db, KnownClass::Object)
}
},

(Type::StringLiteral(string), other) | (other, Type::StringLiteral(string)) => {
Expand All @@ -615,7 +624,10 @@ impl<'db> Type<'db> {
Type::StringLiteral(string_other) => string != string_other,
Type::LiteralString => false,
Type::BytesLiteral(..) => true,
Type::Instance(..) => false,
Type::Instance(class_type) => {
!class_type.is_known(db, KnownClass::Str)
&& !class_type.is_known(db, KnownClass::Object)
}
}
}

Expand Down

0 comments on commit 215ef0c

Please sign in to comment.