@@ -4,15 +4,16 @@ use super::{PY_CF_OPTIMIZED_AST, PY_CF_TYPE_COMMENTS, PY_COMPILE_FLAG_AST_ONLY};
44pub ( crate ) mod _ast {
55 use crate :: {
66 AsObject , Context , PyObjectRef , PyPayload , PyResult , VirtualMachine ,
7- builtins:: { PyStrRef , PyTupleRef } ,
7+ builtins:: { PyStrRef , PyTupleRef , PyTypeRef } ,
88 function:: FuncArgs ,
9+ types:: Constructor ,
910 } ;
1011 #[ pyattr]
1112 #[ pyclass( module = "_ast" , name = "AST" ) ]
1213 #[ derive( Debug , PyPayload ) ]
1314 pub ( crate ) struct NodeAst ;
1415
15- #[ pyclass( flags( BASETYPE , HAS_DICT ) ) ]
16+ #[ pyclass( with ( Constructor ) , flags( BASETYPE , HAS_DICT ) ) ]
1617 impl NodeAst {
1718 #[ pyslot]
1819 #[ pymethod]
@@ -52,6 +53,34 @@ pub(crate) mod _ast {
5253 }
5354 }
5455
56+ impl Constructor for NodeAst {
57+ type Args = FuncArgs ;
58+
59+ fn slot_new ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
60+ // AST nodes accept extra arguments (unlike object.__new__)
61+ // This matches CPython's behavior where AST has its own tp_new
62+ let dict = if cls
63+ . slots
64+ . flags
65+ . contains ( crate :: types:: PyTypeFlags :: HAS_DICT )
66+ {
67+ Some ( vm. ctx . new_dict ( ) )
68+ } else {
69+ None
70+ } ;
71+ let zelf = vm. ctx . new_base_object ( cls, dict) ;
72+
73+ // Initialize the instance with the provided arguments
74+ NodeAst :: __init__ ( zelf. clone ( ) , args, vm) ?;
75+
76+ Ok ( zelf)
77+ }
78+
79+ fn py_new ( _cls : PyTypeRef , _args : Self :: Args , _vm : & VirtualMachine ) -> PyResult {
80+ unreachable ! ( "slow_new is implemented" ) ;
81+ }
82+ }
83+
5584 #[ pyattr( name = "PyCF_ONLY_AST" ) ]
5685 use super :: PY_COMPILE_FLAG_AST_ONLY ;
5786
0 commit comments