127
127
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
128
128
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .NoGeneralizationNode ;
129
129
import com .oracle .graal .python .builtins .objects .complex .PComplex ;
130
+ import com .oracle .graal .python .builtins .objects .dict .DictBuiltins ;
130
131
import com .oracle .graal .python .builtins .objects .dict .PDict ;
131
132
import com .oracle .graal .python .builtins .objects .enumerate .PEnumerate ;
132
133
import com .oracle .graal .python .builtins .objects .floats .FloatBuiltins ;
177
178
import com .oracle .graal .python .nodes .ErrorMessages ;
178
179
import com .oracle .graal .python .nodes .PGuards ;
179
180
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
181
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__QUALNAME__ ;
180
182
import com .oracle .graal .python .nodes .SpecialMethodNames ;
181
183
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
182
184
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
@@ -2074,7 +2076,7 @@ Object type(Object cls, Object obj, PNone bases, PNone dict, PKeyword[] kwds,
2074
2076
}
2075
2077
2076
2078
@ Specialization (guards = "isString(wName)" )
2077
- Object typeNew (VirtualFrame frame , Object cls , Object wName , PTuple bases , PDict namespace , PKeyword [] kwds ,
2079
+ Object typeNew (VirtualFrame frame , Object cls , Object wName , PTuple bases , PDict namespaceOrig , PKeyword [] kwds ,
2078
2080
@ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
2079
2081
@ CachedLibrary (limit = "2" ) HashingStorageLibrary nslib ,
2080
2082
@ Cached BranchProfile updatedStorage ,
@@ -2085,8 +2087,9 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
2085
2087
@ Cached CallNode callSetNameNode ,
2086
2088
@ Cached CallNode callInitSubclassNode ,
2087
2089
@ Cached CallNode callNewFuncNode ,
2090
+ @ Cached ("create(__DICT__)" ) LookupAttributeInMRONode getDictAttrNode ,
2088
2091
@ Cached GetBestBaseClassNode getBestBaseNode ,
2089
- @ Cached ( "create(__DICT__)" ) LookupAttributeInMRONode getDictAttrNode ) {
2092
+ @ Cached DictBuiltins . CopyNode copyDict ) {
2090
2093
// Determine the proper metatype to deal with this
2091
2094
String name = castStr .execute (wName );
2092
2095
Object metaclass = calculate_metaclass (frame , cls , bases , lib );
@@ -2096,11 +2099,12 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
2096
2099
// the new metaclass has the same __new__ function as we are in, continue
2097
2100
} else {
2098
2101
// Pass it to the winner
2099
- callNewFuncNode .execute (frame , newFunc , new Object []{metaclass , name , bases , namespace }, kwds );
2102
+ callNewFuncNode .execute (frame , newFunc , new Object []{metaclass , name , bases , namespaceOrig }, kwds );
2100
2103
}
2101
2104
}
2102
2105
2103
2106
try {
2107
+ PDict namespace = (PDict ) copyDict .call (frame , namespaceOrig );
2104
2108
PythonClass newType = typeMetaclass (frame , name , bases , namespace , metaclass , nslib , getDictAttrNode , getBestBaseNode );
2105
2109
2106
2110
for (DictEntry entry : nslib .entries (namespace .getDictStorage ())) {
@@ -2132,6 +2136,15 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
2132
2136
}
2133
2137
}
2134
2138
2139
+ // delete __qualname__ from namespace
2140
+ if (nslib .hasKey (namespace .getDictStorage (), __QUALNAME__ )) {
2141
+ HashingStorage newStore = nslib .delItem (namespace .getDictStorage (), __QUALNAME__ );
2142
+ if (newStore != namespace .getDictStorage ()) {
2143
+ updatedStorage .enter ();
2144
+ namespace .setDictStorage (newStore );
2145
+ }
2146
+ }
2147
+
2135
2148
// set __class__ cell contents
2136
2149
Object classcell = nslib .getItem (namespace .getDictStorage (), __CLASSCELL__ );
2137
2150
if (classcell != null ) {
@@ -2434,7 +2447,8 @@ private PTuple copySlots(String className, SequenceStorage slotList, int slotlen
2434
2447
setSlotItemNode ().execute (newSlots , slotName , NoGeneralizationNode .DEFAULT );
2435
2448
// Passing 'null' frame is fine because the caller already transfers the exception
2436
2449
// state to the context.
2437
- if (nslib .hasKey (namespace .getDictStorage (), slotName )) {
2450
+ if (!slotName .equals (__CLASSCELL__ ) && !slotName .equals (__QUALNAME__ ) && nslib .hasKey (namespace .getDictStorage (), slotName )) {
2451
+ // __qualname__ and __classcell__ will be deleted later
2438
2452
throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .S_S_CONFLICTS_WITH_CLASS_VARIABLE , slotName , "__slots__" );
2439
2453
}
2440
2454
j ++;
0 commit comments