@@ -936,9 +936,9 @@ impl Constructor for PyType {
936
936
return Err ( vm. new_value_error ( "type name must not contain null characters" ) ) ;
937
937
}
938
938
939
- let ( metatype, base, bases) = if bases. is_empty ( ) {
939
+ let ( metatype, base, bases, base_is_type ) = if bases. is_empty ( ) {
940
940
let base = vm. ctx . types . object_type . to_owned ( ) ;
941
- ( metatype, base. clone ( ) , vec ! [ base] )
941
+ ( metatype, base. clone ( ) , vec ! [ base] , false )
942
942
} else {
943
943
let bases = bases
944
944
. iter ( )
@@ -972,8 +972,9 @@ impl Constructor for PyType {
972
972
} ;
973
973
974
974
let base = best_base ( & bases, vm) ?;
975
+ let base_is_type = base. is ( vm. ctx . types . type_type ) ;
975
976
976
- ( metatype, base. to_owned ( ) , bases)
977
+ ( metatype, base. to_owned ( ) , bases, base_is_type )
977
978
} ;
978
979
979
980
let qualname = dict
@@ -1114,12 +1115,16 @@ impl Constructor for PyType {
1114
1115
// All *classes* should have a dict. Exceptions are *instances* of
1115
1116
// classes that define __slots__ and instances of built-in classes
1116
1117
// (with exceptions, e.g function)
1117
- let __dict__ = identifier ! ( vm, __dict__) ;
1118
- attributes. entry ( __dict__) . or_insert_with ( || unsafe {
1119
- vm. ctx
1120
- . new_getset ( "__dict__" , & typ, subtype_get_dict, subtype_set_dict)
1121
- . into ( )
1122
- } ) ;
1118
+ // Also, type subclasses don't need their own __dict__ descriptor
1119
+ // since they inherit it from type
1120
+ if !base_is_type {
1121
+ let __dict__ = identifier ! ( vm, __dict__) ;
1122
+ attributes. entry ( __dict__) . or_insert_with ( || unsafe {
1123
+ vm. ctx
1124
+ . new_getset ( "__dict__" , & typ, subtype_get_dict, subtype_set_dict)
1125
+ . into ( )
1126
+ } ) ;
1127
+ }
1123
1128
1124
1129
if let Some ( cell) = attributes. get ( identifier ! ( vm, __classcell__) ) {
1125
1130
let cell = PyCellRef :: try_from_object ( vm, cell. clone ( ) ) . map_err ( |_| {
0 commit comments