@@ -2146,23 +2146,24 @@ public abstract static class TypeNode extends PythonBuiltinNode {
2146
2146
@ Specialization (guards = {"isNoValue(bases)" , "isNoValue(dict)" })
2147
2147
@ SuppressWarnings ("unused" )
2148
2148
Object type (Object cls , Object obj , PNone bases , PNone dict , PKeyword [] kwds ,
2149
- @ Cached ( "create()" ) GetClassNode getClass ) {
2149
+ @ Cached GetClassNode getClass ) {
2150
2150
return getClass .execute (obj );
2151
2151
}
2152
2152
2153
- @ Specialization
2154
- Object type (VirtualFrame frame , Object cls , String name , PTuple bases , PDict namespace , PKeyword [] kwds ,
2153
+ @ Specialization ( guards = "isString(wName)" )
2154
+ Object typeNew (VirtualFrame frame , Object cls , Object wName , PTuple bases , PDict namespace , PKeyword [] kwds ,
2155
2155
@ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
2156
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary nslib ,
2157
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary glib ,
2156
+ @ CachedLibrary (limit = "2" ) HashingStorageLibrary nslib ,
2158
2157
@ Cached BranchProfile updatedStorage ,
2159
2158
@ Cached ("create(__NEW__)" ) LookupInheritedAttributeNode getNewFuncNode ,
2160
2159
@ Cached ("create(__INIT_SUBCLASS__)" ) GetAttributeNode getInitSubclassNode ,
2161
2160
@ Cached ("create(__SET_NAME__)" ) LookupInheritedAttributeNode getSetNameNode ,
2161
+ @ Cached CastToJavaStringNode castStr ,
2162
2162
@ Cached CallNode callSetNameNode ,
2163
2163
@ Cached CallNode callInitSubclassNode ,
2164
2164
@ Cached CallNode callNewFuncNode ) {
2165
2165
// Determine the proper metatype to deal with this
2166
+ String name = castStr .execute (wName );
2166
2167
Object metaclass = calculate_metaclass (frame , cls , bases , lib );
2167
2168
if (metaclass != cls ) {
2168
2169
Object newFunc = getNewFuncNode .execute (metaclass );
@@ -2195,7 +2196,7 @@ Object type(VirtualFrame frame, Object cls, String name, PTuple bases, PDict nam
2195
2196
PFrame callerFrame = getReadCallerFrameNode ().executeWith (frame , 0 );
2196
2197
PythonObject globals = callerFrame .getGlobals ();
2197
2198
if (globals != null ) {
2198
- String moduleName = getModuleNameFromGlobals (globals , glib );
2199
+ String moduleName = getModuleNameFromGlobals (globals , nslib );
2199
2200
if (moduleName != null ) {
2200
2201
ensureWriteAttrNode ().execute (frame , newType , __MODULE__ , moduleName );
2201
2202
}
@@ -2225,6 +2226,19 @@ Object type(VirtualFrame frame, Object cls, String name, PTuple bases, PDict nam
2225
2226
}
2226
2227
}
2227
2228
2229
+ @ Fallback
2230
+ Object generic (Object cls , Object name , Object bases , Object namespace , Object kwds ) {
2231
+ if (!(bases instanceof PTuple )) {
2232
+ throw raise (TypeError , ErrorMessages .ARG_D_MUST_BE_S_NOT_P , "type.__new__()" , 2 , "tuple" , bases );
2233
+ } else if (namespace == PNone .NO_VALUE ) {
2234
+ throw raise (TypeError , ErrorMessages .TAKES_D_OR_D_ARGS , "type()" , 1 , 3 );
2235
+ } else if (!(namespace instanceof PDict )) {
2236
+ throw raise (TypeError , ErrorMessages .ARG_D_MUST_BE_S_NOT_P , "type.__new__()" , 3 , "dict" , bases );
2237
+ } else {
2238
+ throw CompilerDirectives .shouldNotReachHere ("type fallback reached incorrectly" );
2239
+ }
2240
+ }
2241
+
2228
2242
private String getModuleNameFromGlobals (PythonObject globals , HashingStorageLibrary hlib ) {
2229
2243
Object nameAttr ;
2230
2244
if (globals instanceof PythonModule ) {
0 commit comments