@@ -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
@@ -1021,17 +1022,21 @@ impl Constructor for PyType {
1021
1022
// All *classes* should have a dict. Exceptions are *instances* of
1022
1023
// classes that define __slots__ and instances of built-in classes
1023
1024
// (with exceptions, e.g function)
1024
- let __dict__ = identifier ! ( vm, __dict__) ;
1025
- attributes. entry ( __dict__) . or_insert_with ( || {
1026
- vm. ctx
1027
- . new_static_getset (
1028
- "__dict__" ,
1029
- vm. ctx . types . type_type ,
1030
- subtype_get_dict,
1031
- subtype_set_dict,
1032
- )
1033
- . into ( )
1034
- } ) ;
1025
+ // Also, type subclasses don't need their own __dict__ descriptor
1026
+ // since they inherit it from type
1027
+ if !base_is_type {
1028
+ let __dict__ = identifier ! ( vm, __dict__) ;
1029
+ attributes. entry ( __dict__) . or_insert_with ( || {
1030
+ vm. ctx
1031
+ . new_static_getset (
1032
+ "__dict__" ,
1033
+ vm. ctx . types . type_type ,
1034
+ subtype_get_dict,
1035
+ subtype_set_dict,
1036
+ )
1037
+ . into ( )
1038
+ } ) ;
1039
+ }
1035
1040
1036
1041
// TODO: Flags is currently initialized with HAS_DICT. Should be
1037
1042
// updated when __slots__ are supported (toggling the flag off if
0 commit comments