@@ -1019,25 +1019,6 @@ impl Constructor for PyType {
1019
1019
attributes. insert ( identifier ! ( vm, __hash__) , vm. ctx . none . clone ( ) . into ( ) ) ;
1020
1020
}
1021
1021
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
-
1041
1022
let heaptype_slots: Option < PyRef < PyTuple < PyStrRef > > > =
1042
1023
if let Some ( x) = attributes. get ( identifier ! ( vm, __slots__) ) {
1043
1024
let slots = if x. class ( ) . is ( vm. ctx . types . str_type ) {
@@ -1141,6 +1122,24 @@ impl Constructor for PyType {
1141
1122
cell. set ( Some ( typ. clone ( ) . into ( ) ) ) ;
1142
1123
} ;
1143
1124
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
+
1144
1143
// avoid deadlock
1145
1144
let attributes = typ
1146
1145
. attributes
0 commit comments