119
119
import com .oracle .graal .python .builtins .objects .set .PSet ;
120
120
import com .oracle .graal .python .builtins .objects .set .SetNodes ;
121
121
import com .oracle .graal .python .builtins .objects .str .PString ;
122
+ import com .oracle .graal .python .builtins .objects .superobject .SuperObject ;
122
123
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
123
124
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
124
125
import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
130
131
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
131
132
import com .oracle .graal .python .nodes .PGuards ;
132
133
import com .oracle .graal .python .nodes .SpecialMethodNames ;
134
+ import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
133
135
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
134
136
import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
135
137
import com .oracle .graal .python .nodes .attributes .LookupInheritedAttributeNode ;
@@ -1813,6 +1815,8 @@ public Object type(Object cls, Object obj, PNone bases, PNone dict, PKeyword[] k
1813
1815
public Object type (VirtualFrame frame , PythonAbstractClass cls , String name , PTuple bases , PDict namespace , PKeyword [] kwds ,
1814
1816
@ Cached ("create()" ) GetClassNode getMetaclassNode ,
1815
1817
@ Cached ("create(__NEW__)" ) LookupInheritedAttributeNode getNewFuncNode ,
1818
+ @ Cached ("create(__INIT_SUBCLASS__)" ) GetAttributeNode getInitSubclassNode ,
1819
+ @ Cached ("create()" ) CallNode callInitSubclassNode ,
1816
1820
@ Cached ("create()" ) CallNode callNewFuncNode ) {
1817
1821
// Determine the proper metatype to deal with this
1818
1822
PythonAbstractClass metaclass = calculate_metaclass (cls , bases , getMetaclassNode );
@@ -1827,7 +1831,14 @@ public Object type(VirtualFrame frame, PythonAbstractClass cls, String name, PTu
1827
1831
}
1828
1832
1829
1833
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 );
1831
1842
1832
1843
// set '__module__' attribute
1833
1844
Object moduleAttr = ensureReadAttrNode ().execute (newType , __MODULE__ );
@@ -1863,7 +1874,7 @@ private String getModuleNameFromGlobals(PythonObject globals) {
1863
1874
}
1864
1875
1865
1876
@ 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 ) {
1867
1878
1868
1879
Object [] array = bases .getArray ();
1869
1880
0 commit comments