[red-knot] Type::SubclassOf(SubclassOfType { base: ClassBase::Unknown }).to_instance() should be Unknown, not Any (#15269)

This commit is contained in:
Alex Waygood 2025-01-05 15:14:01 +00:00 committed by GitHub
parent f144b9684d
commit eb82089551
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1952,10 +1952,12 @@ impl<'db> Type<'db> {
Type::Unknown => Type::Unknown,
Type::Never => Type::Never,
Type::ClassLiteral(ClassLiteralType { class }) => Type::instance(*class),
Type::SubclassOf(SubclassOfType {
base: ClassBase::Class(class),
}) => Type::instance(*class),
Type::SubclassOf(_) => Type::Any,
Type::SubclassOf(SubclassOfType { base }) => match base {
ClassBase::Class(class) => Type::instance(*class),
ClassBase::Any => Type::Any,
ClassBase::Unknown => Type::Unknown,
ClassBase::Todo(todo) => Type::Todo(*todo),
},
Type::Union(union) => union.map(db, |element| element.to_instance(db)),
Type::Intersection(_) => todo_type!("Type::Intersection.to_instance()"),
// TODO: calling `.to_instance()` on any of these should result in a diagnostic,