@@ -9389,23 +9389,24 @@ impl<'db> BoundSuperType<'db> {
93899389 ) ) ;
93909390 }
93919391
9392- // TODO: having to get a class-literal just to pass it in here is silly.
9393- // `BoundSuperType` should probably not be using `ClassBase::try_from_type` here;
9394- // this also leads to false negatives in some cases. See discussion in
9395- // <https://github.com/astral-sh/ruff/pull/19560#discussion_r2271570071>.
9396- let pivot_class = ClassBase :: try_from_type (
9397- db,
9398- pivot_class_type,
9399- KnownClass :: Object
9400- . to_class_literal ( db)
9401- . into_class_literal ( )
9402- . expect ( "`object` should always exist in typeshed" ) ,
9403- )
9404- . ok_or ( {
9405- BoundSuperError :: InvalidPivotClassType {
9406- pivot_class : pivot_class_type,
9392+ // We don't use `Classbase::try_from_type` here because:
9393+ // - There are objects that may validly be present in a class's bases list
9394+ // but are not valid as pivot classes, e.g. `typing.ChainMap`
9395+ // - There are objects that are not valid in a class's bases list
9396+ // but are valid as pivot classes, e.g. unsubscripted `typing.Generic`
9397+ let pivot_class = match pivot_class_type {
9398+ Type :: ClassLiteral ( class) => ClassBase :: Class ( ClassType :: NonGeneric ( class) ) ,
9399+ Type :: GenericAlias ( class) => ClassBase :: Class ( ClassType :: Generic ( class) ) ,
9400+ Type :: SpecialForm ( SpecialFormType :: Protocol ) => ClassBase :: Protocol ,
9401+ Type :: SpecialForm ( SpecialFormType :: Generic ) => ClassBase :: Generic ,
9402+ Type :: SpecialForm ( SpecialFormType :: TypedDict ) => ClassBase :: TypedDict ,
9403+ Type :: Dynamic ( dynamic) => ClassBase :: Dynamic ( dynamic) ,
9404+ _ => {
9405+ return Err ( BoundSuperError :: InvalidPivotClassType {
9406+ pivot_class : pivot_class_type,
9407+ } ) ;
94079408 }
9408- } ) ? ;
9409+ } ;
94099410
94109411 let owner = SuperOwnerKind :: try_from_type ( db, owner_type)
94119412 . and_then ( |owner| {
0 commit comments