119119import com .oracle .graal .python .builtins .objects .set .PSet ;
120120import com .oracle .graal .python .builtins .objects .set .SetNodes ;
121121import com .oracle .graal .python .builtins .objects .str .PString ;
122+ import com .oracle .graal .python .builtins .objects .superobject .SuperObject ;
122123import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
123124import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
124125import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
130131import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
131132import com .oracle .graal .python .nodes .PGuards ;
132133import com .oracle .graal .python .nodes .SpecialMethodNames ;
134+ import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
133135import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
134136import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
135137import com .oracle .graal .python .nodes .attributes .LookupInheritedAttributeNode ;
@@ -1813,6 +1815,8 @@ public Object type(Object cls, Object obj, PNone bases, PNone dict, PKeyword[] k
18131815 public Object type (VirtualFrame frame , PythonAbstractClass cls , String name , PTuple bases , PDict namespace , PKeyword [] kwds ,
18141816 @ Cached ("create()" ) GetClassNode getMetaclassNode ,
18151817 @ Cached ("create(__NEW__)" ) LookupInheritedAttributeNode getNewFuncNode ,
1818+ @ Cached ("create(__INIT_SUBCLASS__)" ) GetAttributeNode getInitSubclassNode ,
1819+ @ Cached ("create()" ) CallNode callInitSubclassNode ,
18161820 @ Cached ("create()" ) CallNode callNewFuncNode ) {
18171821 // Determine the proper metatype to deal with this
18181822 PythonAbstractClass metaclass = calculate_metaclass (cls , bases , getMetaclassNode );
@@ -1827,7 +1831,14 @@ public Object type(VirtualFrame frame, PythonAbstractClass cls, String name, PTu
18271831 }
18281832
18291833 try {
1830- Object newType = typeMetaclass (name , bases , namespace , metaclass );
1834+ PythonClass newType = typeMetaclass (name , bases , namespace , metaclass );
1835+
1836+ // TODO: Call __set_name__ on all descriptors in a newly generated type
1837+
1838+ // Call __init_subclass__ on the parent of a newly generated type
1839+ SuperObject superObject = factory ().createSuperObject (PythonBuiltinClassType .Super );
1840+ superObject .init (newType , newType , newType );
1841+ callInitSubclassNode .execute (frame , getInitSubclassNode .executeObject (superObject ), new Object [0 ], kwds );
18311842
18321843 // set '__module__' attribute
18331844 Object moduleAttr = ensureReadAttrNode ().execute (newType , __MODULE__ );
@@ -1863,7 +1874,7 @@ private String getModuleNameFromGlobals(PythonObject globals) {
18631874 }
18641875
18651876 @ TruffleBoundary
1866- private Object typeMetaclass (String name , PTuple bases , PDict namespace , PythonAbstractClass metaclass ) {
1877+ private PythonClass typeMetaclass (String name , PTuple bases , PDict namespace , PythonAbstractClass metaclass ) {
18671878
18681879 Object [] array = bases .getArray ();
18691880
0 commit comments