26
26
27
27
package com .oracle .graal .python .builtins .objects .type ;
28
28
29
+ import static com .oracle .graal .python .builtins .objects .str .StringUtils .canEncodeUTF8 ;
29
30
import static com .oracle .graal .python .builtins .objects .str .StringUtils .containsNullCharacter ;
30
31
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__ABSTRACTMETHODS__ ;
31
32
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__BASES__ ;
83
84
import com .oracle .graal .python .builtins .objects .list .PList ;
84
85
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
85
86
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
86
- import static com .oracle .graal .python .builtins .objects .str .StringUtils .canEncodeUTF8 ;
87
87
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
88
88
import com .oracle .graal .python .builtins .objects .type .TypeBuiltinsFactory .CallNodeFactory ;
89
89
import com .oracle .graal .python .builtins .objects .type .TypeNodes .CheckCompatibleForAssigmentNode ;
@@ -1255,9 +1255,9 @@ Object doGeneric(Object self,
1255
1255
}
1256
1256
}
1257
1257
1258
- @ Builtin (name = __ABSTRACTMETHODS__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true )
1258
+ @ Builtin (name = __ABSTRACTMETHODS__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 2 , isGetter = true , isSetter = true , allowsDelete = true )
1259
1259
@ GenerateNodeFactory
1260
- abstract static class AbstracMethodsNode extends PythonBinaryBuiltinNode {
1260
+ abstract static class AbstractMethodsNode extends PythonBinaryBuiltinNode {
1261
1261
@ Specialization (guards = "isNoValue(none)" )
1262
1262
Object get (Object self , @ SuppressWarnings ("unused" ) PNone none ,
1263
1263
@ Cached IsSameTypeNode isSameTypeNode ,
@@ -1272,13 +1272,32 @@ Object get(Object self, @SuppressWarnings("unused") PNone none,
1272
1272
throw raise (AttributeError , ErrorMessages .OBJ_S_HAS_NO_ATTR_S , GetNameNode .getUncached ().execute (self ), __ABSTRACTMETHODS__ );
1273
1273
}
1274
1274
1275
- @ Specialization (guards = "!isNoValue(value)" , limit = "3" )
1276
- static Object set (VirtualFrame frame , PythonClass self , Object value ,
1275
+ @ Specialization (guards = { "!isNoValue(value)" , "!isDeleteMarker(value)" } , limit = "3" )
1276
+ Object set (VirtualFrame frame , PythonClass self , Object value ,
1277
1277
@ CachedLibrary ("value" ) PythonObjectLibrary lib ,
1278
+ @ Cached IsSameTypeNode isSameTypeNode ,
1278
1279
@ Cached WriteAttributeToObjectNode writeAttributeToObjectNode ) {
1279
- writeAttributeToObjectNode .execute (self , __ABSTRACTMETHODS__ , value );
1280
- self .setAbstractClass (lib .isTrue (value , frame ));
1281
- return PNone .NONE ;
1280
+ if (!isSameTypeNode .execute (self , PythonBuiltinClassType .PythonClass )) {
1281
+ writeAttributeToObjectNode .execute (self , __ABSTRACTMETHODS__ , value );
1282
+ self .setAbstractClass (lib .isTrue (value , frame ));
1283
+ return PNone .NONE ;
1284
+ }
1285
+ throw raise (AttributeError , ErrorMessages .CANT_SET_ATTRIBUTES_OF_TYPE_S , GetNameNode .getUncached ().execute (self ));
1286
+ }
1287
+
1288
+ @ Specialization (guards = "!isNoValue(value)" )
1289
+ Object delete (PythonClass self , @ SuppressWarnings ("unused" ) DescriptorDeleteMarker value ,
1290
+ @ Cached IsSameTypeNode isSameTypeNode ,
1291
+ @ Cached ReadAttributeFromObjectNode readAttributeFromObjectNode ,
1292
+ @ Cached WriteAttributeToObjectNode writeAttributeToObjectNode ) {
1293
+ if (!isSameTypeNode .execute (self , PythonBuiltinClassType .PythonClass )) {
1294
+ if (readAttributeFromObjectNode .execute (self , __ABSTRACTMETHODS__ ) != PNone .NO_VALUE ) {
1295
+ writeAttributeToObjectNode .execute (self , __ABSTRACTMETHODS__ , PNone .NO_VALUE );
1296
+ self .setAbstractClass (false );
1297
+ return PNone .NONE ;
1298
+ }
1299
+ }
1300
+ throw raise (AttributeError , ErrorMessages .CANT_SET_ATTRIBUTES_OF_TYPE_S , GetNameNode .getUncached ().execute (self ));
1282
1301
}
1283
1302
1284
1303
@ Fallback
0 commit comments