@@ -2146,23 +2146,24 @@ public abstract static class TypeNode extends PythonBuiltinNode {
21462146 @ Specialization (guards = {"isNoValue(bases)" , "isNoValue(dict)" })
21472147 @ SuppressWarnings ("unused" )
21482148 Object type (Object cls , Object obj , PNone bases , PNone dict , PKeyword [] kwds ,
2149- @ Cached ( "create()" ) GetClassNode getClass ) {
2149+ @ Cached GetClassNode getClass ) {
21502150 return getClass .execute (obj );
21512151 }
21522152
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 ,
21552155 @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
2156- @ CachedLibrary (limit = "1" ) HashingStorageLibrary nslib ,
2157- @ CachedLibrary (limit = "1" ) HashingStorageLibrary glib ,
2156+ @ CachedLibrary (limit = "2" ) HashingStorageLibrary nslib ,
21582157 @ Cached BranchProfile updatedStorage ,
21592158 @ Cached ("create(__NEW__)" ) LookupInheritedAttributeNode getNewFuncNode ,
21602159 @ Cached ("create(__INIT_SUBCLASS__)" ) GetAttributeNode getInitSubclassNode ,
21612160 @ Cached ("create(__SET_NAME__)" ) LookupInheritedAttributeNode getSetNameNode ,
2161+ @ Cached CastToJavaStringNode castStr ,
21622162 @ Cached CallNode callSetNameNode ,
21632163 @ Cached CallNode callInitSubclassNode ,
21642164 @ Cached CallNode callNewFuncNode ) {
21652165 // Determine the proper metatype to deal with this
2166+ String name = castStr .execute (wName );
21662167 Object metaclass = calculate_metaclass (frame , cls , bases , lib );
21672168 if (metaclass != cls ) {
21682169 Object newFunc = getNewFuncNode .execute (metaclass );
@@ -2195,7 +2196,7 @@ Object type(VirtualFrame frame, Object cls, String name, PTuple bases, PDict nam
21952196 PFrame callerFrame = getReadCallerFrameNode ().executeWith (frame , 0 );
21962197 PythonObject globals = callerFrame .getGlobals ();
21972198 if (globals != null ) {
2198- String moduleName = getModuleNameFromGlobals (globals , glib );
2199+ String moduleName = getModuleNameFromGlobals (globals , nslib );
21992200 if (moduleName != null ) {
22002201 ensureWriteAttrNode ().execute (frame , newType , __MODULE__ , moduleName );
22012202 }
@@ -2225,6 +2226,19 @@ Object type(VirtualFrame frame, Object cls, String name, PTuple bases, PDict nam
22252226 }
22262227 }
22272228
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+
22282242 private String getModuleNameFromGlobals (PythonObject globals , HashingStorageLibrary hlib ) {
22292243 Object nameAttr ;
22302244 if (globals instanceof PythonModule ) {
0 commit comments