@@ -1018,21 +1018,6 @@ impl Constructor for PyType {
1018
1018
attributes. insert ( identifier ! ( vm, __hash__) , vm. ctx . none . clone ( ) . into ( ) ) ;
1019
1019
}
1020
1020
1021
- // All *classes* should have a dict. Exceptions are *instances* of
1022
- // classes that define __slots__ and instances of built-in classes
1023
- // (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
- } ) ;
1035
-
1036
1021
// TODO: Flags is currently initialized with HAS_DICT. Should be
1037
1022
// updated when __slots__ are supported (toggling the flag off if
1038
1023
// a class has __slots__ defined).
@@ -1124,15 +1109,28 @@ impl Constructor for PyType {
1124
1109
}
1125
1110
}
1126
1111
1127
- if let Some ( cell) = typ. attributes . write ( ) . get ( identifier ! ( vm, __classcell__) ) {
1128
- let cell = PyCellRef :: try_from_object ( vm, cell. clone ( ) ) . map_err ( |_| {
1129
- vm. new_type_error ( format ! (
1130
- "__classcell__ must be a nonlocal cell, not {}" ,
1131
- cell. class( ) . name( )
1132
- ) )
1133
- } ) ?;
1134
- cell. set ( Some ( typ. clone ( ) . into ( ) ) ) ;
1135
- } ;
1112
+ {
1113
+ let mut attributes = typ. attributes . write ( ) ;
1114
+ // All *classes* should have a dict. Exceptions are *instances* of
1115
+ // classes that define __slots__ and instances of built-in classes
1116
+ // (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
+ } ) ;
1123
+
1124
+ if let Some ( cell) = attributes. get ( identifier ! ( vm, __classcell__) ) {
1125
+ let cell = PyCellRef :: try_from_object ( vm, cell. clone ( ) ) . map_err ( |_| {
1126
+ vm. new_type_error ( format ! (
1127
+ "__classcell__ must be a nonlocal cell, not {}" ,
1128
+ cell. class( ) . name( )
1129
+ ) )
1130
+ } ) ?;
1131
+ cell. set ( Some ( typ. clone ( ) . into ( ) ) ) ;
1132
+ } ;
1133
+ }
1136
1134
1137
1135
// avoid deadlock
1138
1136
let attributes = typ
0 commit comments