@@ -1019,25 +1019,6 @@ impl Constructor for PyType {
10191019 attributes. insert ( identifier ! ( vm, __hash__) , vm. ctx . none . clone ( ) . into ( ) ) ;
10201020 }
10211021
1022- // All *classes* should have a dict. Exceptions are *instances* of
1023- // classes that define __slots__ and instances of built-in classes
1024- // (with exceptions, e.g function)
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- }
1040-
10411022 let heaptype_slots: Option < PyRef < PyTuple < PyStrRef > > > =
10421023 if let Some ( x) = attributes. get ( identifier ! ( vm, __slots__) ) {
10431024 let slots = if x. class ( ) . is ( vm. ctx . types . str_type ) {
@@ -1141,6 +1122,24 @@ impl Constructor for PyType {
11411122 cell. set ( Some ( typ. clone ( ) . into ( ) ) ) ;
11421123 } ;
11431124
1125+ // All *classes* should have a dict. Exceptions are *instances* of
1126+ // classes that define __slots__ and instances of built-in classes
1127+ // (with exceptions, e.g function)
1128+ // Also, type subclasses don't need their own __dict__ descriptor
1129+ // since they inherit it from type
1130+
1131+ // Add __dict__ descriptor after type creation to ensure correct __objclass__
1132+ if !base_is_type {
1133+ unsafe {
1134+ let descriptor =
1135+ vm. ctx
1136+ . new_getset ( "__dict__" , & typ, subtype_get_dict, subtype_set_dict) ;
1137+ typ. attributes
1138+ . write ( )
1139+ . insert ( identifier ! ( vm, __dict__) , descriptor. into ( ) ) ;
1140+ }
1141+ }
1142+
11441143 // avoid deadlock
11451144 let attributes = typ
11461145 . attributes
0 commit comments