From 611dcc2e9b2440fc4a6fb48ff80e14a0f2670931 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Tue, 16 May 2023 18:06:54 +0900 Subject: [PATCH] rustpython_ast + pyo3 (#25) --- Cargo.toml | 1 + ast/Cargo.toml | 3 + ast/asdl_rs.py | 182 +++ ast/src/gen/to_pyo3.rs | 3353 ++++++++++++++++++++++++++++++++++++++++ ast/src/lib.rs | 3 + ast/src/pyo3.rs | 116 ++ 6 files changed, 3658 insertions(+) create mode 100644 ast/src/gen/to_pyo3.rs create mode 100644 ast/src/pyo3.rs diff --git a/Cargo.toml b/Cargo.toml index 38cedc5320..b37c6cfdc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ log = "0.4.16" num-complex = "0.4.0" num-bigint = "0.4.3" num-traits = "0.2" +pyo3 = { version = "0.18.3" } rand = "0.8.5" serde = "1.0" static_assertions = "1.1" diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 3f4f3903f6..dfd18c4666 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -23,3 +23,6 @@ rustpython-literal = { workspace = true, optional = true } is-macro = { workspace = true } num-bigint = { workspace = true } static_assertions = "1.1.0" +num-complex = { workspace = true } +once_cell = { workspace = true } +pyo3 = { workspace = true, optional = true, features = ["num-bigint", "num-complex"] } diff --git a/ast/asdl_rs.py b/ast/asdl_rs.py index 6b4f2e240a..e5e5bcf1c1 100755 --- a/ast/asdl_rs.py +++ b/ast/asdl_rs.py @@ -937,6 +937,111 @@ class LocatedDefVisitor(EmitVisitor): ) +class ToPyo3AstVisitor(EmitVisitor): + """Visitor to generate type-defs for AST.""" + + def __init__(self, namespace, *args, **kw): + super().__init__(*args, **kw) + self.namespace = namespace + + @property + def generics(self): + if self.namespace == "ranged": + return "" + elif self.namespace == "located": + return "" + else: + assert False, self.namespace + + def visitModule(self, mod): + for dfn in mod.dfns: + self.visit(dfn) + + def visitType(self, type, depth=0): + self.visit(type.value, type.name, depth) + + def visitProduct(self, product, name, depth=0): + rust_name = rust_type_name(name) + self.emit_to_pyo3_with_fields(product, rust_name) + + def visitSum(self, sum, name, depth=0): + rust_name = rust_type_name(name) + simple = is_simple(sum) + if is_simple(sum): + return + + self.emit( + f""" + impl ToPyo3Ast for crate::generic::{rust_name}{self.generics} {{ + #[inline] + fn to_pyo3_ast(&self, {"_" if simple else ""}py: Python) -> PyResult> {{ + let instance = match &self {{ + """, + 0, + ) + for cons in sum.types: + self.emit( + f"""crate::{rust_name}::{cons.name}(cons) => cons.to_pyo3_ast(py)?,""", + depth, + ) + self.emit( + """ + }; + Ok(instance) + } + } + """, + 0, + ) + + for cons in sum.types: + self.visit(cons, rust_name, depth) + + def visitConstructor(self, cons, parent, depth): + self.emit_to_pyo3_with_fields(cons, f"{parent}{cons.name}") + + def emit_to_pyo3_with_fields(self, cons, name): + if cons.fields: + self.emit( + f""" + impl ToPyo3Ast for crate::{name}{self.generics} {{ + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> {{ + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, ( + """, + 0, + ) + for field in cons.fields: + self.emit( + f"self.{rust_field(field.name)}.to_pyo3_ast(py)?,", + 3, + ) + self.emit( + """ + ))?; + Ok(instance) + } + } + """, + 0, + ) + else: + self.emit( + f""" + impl ToPyo3Ast for crate::{name}{self.generics} {{ + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> {{ + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + }} + }} + """, + 0, + ) + + class StdlibClassDefVisitor(EmitVisitor): def visitModule(self, mod): for dfn in mod.dfns: @@ -1271,6 +1376,82 @@ def write_located_def(mod, type_info, f): LocatedDefVisitor(f, type_info).visit(mod) +def write_pyo3_node(type_info, f): + def write(info: TypeInfo): + rust_name = info.rust_sum_name + if info.is_simple: + generics = "" + else: + generics = "" + + f.write( + textwrap.dedent( + f""" + impl{generics} Pyo3Node for crate::generic::{rust_name}{generics} {{ + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> {{ + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + }} + }} + """ + ), + ) + + for info in type_info.values(): + write(info) + + +def write_to_pyo3(mod, type_info, f): + write_pyo3_node(type_info, f) + write_to_pyo3_simple(type_info, f) + + for namespace in ("ranged", "located"): + ToPyo3AstVisitor(namespace, f, type_info).visit(mod) + + f.write( + """ + pub fn init(py: Python) -> PyResult<()> { + let ast_module = PyModule::import(py, "_ast")?; + """ + ) + + for info in type_info.values(): + rust_name = info.rust_sum_name + f.write(f"cache_py_type::(ast_module)?;\n") + f.write("Ok(())\n}") + + +def write_to_pyo3_simple(type_info, f): + for type_info in type_info.values(): + if not type_info.is_sum: + continue + if not type_info.is_simple: + continue + + rust_name = type_info.rust_sum_name + f.write( + f""" + impl ToPyo3Ast for crate::generic::{rust_name} {{ + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> {{ + let cell = match &self {{ + """, + ) + for cons in type_info.type.value.types: + f.write( + f"""crate::{rust_name}::{cons.name} => crate::{rust_name}{cons.name}::py_type_cache(),""", + ) + f.write( + """ + }; + Ok(cell.get().unwrap().1.clone()) + } + } + """, + ) + + def write_ast_mod(mod, type_info, f): f.write( textwrap.dedent( @@ -1316,6 +1497,7 @@ def main( ("ranged", p(write_ranged_def, mod, type_info)), ("located", p(write_located_def, mod, type_info)), ("visitor", p(write_visitor_def, mod, type_info)), + ("to_pyo3", p(write_to_pyo3, mod, type_info)), ]: with (ast_dir / f"{filename}.rs").open("w") as f: f.write(auto_gen_msg) diff --git a/ast/src/gen/to_pyo3.rs b/ast/src/gen/to_pyo3.rs new file mode 100644 index 0000000000..47786ebd72 --- /dev/null +++ b/ast/src/gen/to_pyo3.rs @@ -0,0 +1,3353 @@ +// File automatically generated by ast/asdl_rs.py. + +impl Pyo3Node for crate::generic::Mod { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ModModule { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ModInteractive { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ModExpression { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ModFunctionType { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Stmt { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtFunctionDef { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAsyncFunctionDef { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtClassDef { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtReturn { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtDelete { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAssign { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAugAssign { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAnnAssign { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtFor { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAsyncFor { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtWhile { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtIf { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtWith { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAsyncWith { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtMatch { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtRaise { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtTry { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtTryStar { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtAssert { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtImport { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtImportFrom { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtGlobal { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtNonlocal { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtExpr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtPass { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtBreak { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::StmtContinue { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Expr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprBoolOp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprNamedExpr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprBinOp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprUnaryOp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprLambda { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprIfExp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprDict { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprSet { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprListComp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprSetComp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprDictComp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprGeneratorExp { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprAwait { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprYield { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprYieldFrom { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprCompare { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprCall { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprFormattedValue { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprJoinedStr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprConstant { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprAttribute { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprSubscript { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprStarred { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprName { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprList { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprTuple { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprSlice { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprContext { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprContextLoad { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprContextStore { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExprContextDel { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Boolop { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::BoolopAnd { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::BoolopOr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Operator { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorAdd { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorSub { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorMult { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorMatMult { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorDiv { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorMod { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorPow { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorLShift { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorRShift { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorBitOr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorBitXor { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorBitAnd { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::OperatorFloorDiv { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Unaryop { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::UnaryopInvert { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::UnaryopNot { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::UnaryopUAdd { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::UnaryopUSub { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Cmpop { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopEq { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopNotEq { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopLt { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopLtE { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopGt { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopGtE { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopIs { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopIsNot { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopIn { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::CmpopNotIn { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Comprehension { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Excepthandler { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::ExcepthandlerExceptHandler { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Arguments { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Arg { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Keyword { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Alias { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Withitem { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::MatchCase { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::Pattern { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchValue { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchSingleton { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchSequence { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchMapping { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchClass { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchStar { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchAs { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::PatternMatchOr { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::TypeIgnore { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl Pyo3Node for crate::generic::TypeIgnoreTypeIgnore { + #[inline] + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } +} + +impl ToPyo3Ast for crate::generic::ExprContext { + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> { + let cell = match &self { + crate::ExprContext::Load => crate::ExprContextLoad::py_type_cache(), + crate::ExprContext::Store => crate::ExprContextStore::py_type_cache(), + crate::ExprContext::Del => crate::ExprContextDel::py_type_cache(), + }; + Ok(cell.get().unwrap().1.clone()) + } +} + +impl ToPyo3Ast for crate::generic::Boolop { + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> { + let cell = match &self { + crate::Boolop::And => crate::BoolopAnd::py_type_cache(), + crate::Boolop::Or => crate::BoolopOr::py_type_cache(), + }; + Ok(cell.get().unwrap().1.clone()) + } +} + +impl ToPyo3Ast for crate::generic::Operator { + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> { + let cell = match &self { + crate::Operator::Add => crate::OperatorAdd::py_type_cache(), + crate::Operator::Sub => crate::OperatorSub::py_type_cache(), + crate::Operator::Mult => crate::OperatorMult::py_type_cache(), + crate::Operator::MatMult => crate::OperatorMatMult::py_type_cache(), + crate::Operator::Div => crate::OperatorDiv::py_type_cache(), + crate::Operator::Mod => crate::OperatorMod::py_type_cache(), + crate::Operator::Pow => crate::OperatorPow::py_type_cache(), + crate::Operator::LShift => crate::OperatorLShift::py_type_cache(), + crate::Operator::RShift => crate::OperatorRShift::py_type_cache(), + crate::Operator::BitOr => crate::OperatorBitOr::py_type_cache(), + crate::Operator::BitXor => crate::OperatorBitXor::py_type_cache(), + crate::Operator::BitAnd => crate::OperatorBitAnd::py_type_cache(), + crate::Operator::FloorDiv => crate::OperatorFloorDiv::py_type_cache(), + }; + Ok(cell.get().unwrap().1.clone()) + } +} + +impl ToPyo3Ast for crate::generic::Unaryop { + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> { + let cell = match &self { + crate::Unaryop::Invert => crate::UnaryopInvert::py_type_cache(), + crate::Unaryop::Not => crate::UnaryopNot::py_type_cache(), + crate::Unaryop::UAdd => crate::UnaryopUAdd::py_type_cache(), + crate::Unaryop::USub => crate::UnaryopUSub::py_type_cache(), + }; + Ok(cell.get().unwrap().1.clone()) + } +} + +impl ToPyo3Ast for crate::generic::Cmpop { + #[inline] + fn to_pyo3_ast(&self, _py: Python) -> PyResult> { + let cell = match &self { + crate::Cmpop::Eq => crate::CmpopEq::py_type_cache(), + crate::Cmpop::NotEq => crate::CmpopNotEq::py_type_cache(), + crate::Cmpop::Lt => crate::CmpopLt::py_type_cache(), + crate::Cmpop::LtE => crate::CmpopLtE::py_type_cache(), + crate::Cmpop::Gt => crate::CmpopGt::py_type_cache(), + crate::Cmpop::GtE => crate::CmpopGtE::py_type_cache(), + crate::Cmpop::Is => crate::CmpopIs::py_type_cache(), + crate::Cmpop::IsNot => crate::CmpopIsNot::py_type_cache(), + crate::Cmpop::In => crate::CmpopIn::py_type_cache(), + crate::Cmpop::NotIn => crate::CmpopNotIn::py_type_cache(), + }; + Ok(cell.get().unwrap().1.clone()) + } +} + +impl ToPyo3Ast for crate::generic::Mod { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Mod::Module(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::Interactive(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::Expression(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::FunctionType(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModModule { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.type_ignores.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModInteractive { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.body.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModExpression { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.body.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModFunctionType { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.argtypes.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Stmt { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Stmt::FunctionDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncFunctionDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::ClassDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Return(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Delete(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Assign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AugAssign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AnnAssign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::For(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncFor(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::While(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::If(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::With(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncWith(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Match(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Raise(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Try(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::TryStar(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Assert(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Import(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::ImportFrom(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Global(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Nonlocal(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Expr(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Pass(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Break(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Continue(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtFunctionDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncFunctionDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtClassDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.bases.to_pyo3_ast(py)?, + self.keywords.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtReturn { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtDelete { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.targets.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.targets.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAugAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.op.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAnnAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.annotation.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.simple.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtFor { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncFor { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtWhile { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtIf { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtWith { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.items.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncWith { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.items.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtMatch { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.subject.to_pyo3_ast(py)?, self.cases.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtRaise { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.exc.to_pyo3_ast(py)?, self.cause.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtTry { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.handlers.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.finalbody.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtTryStar { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.handlers.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.finalbody.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAssert { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.test.to_pyo3_ast(py)?, self.msg.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtImport { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtImportFrom { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.module.to_pyo3_ast(py)?, + self.names.to_pyo3_ast(py)?, + self.level.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtGlobal { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtNonlocal { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtExpr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtPass { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtBreak { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtContinue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Expr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Expr::BoolOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::NamedExpr(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::BinOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::UnaryOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Lambda(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::IfExp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Dict(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Set(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::ListComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::SetComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::DictComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::GeneratorExp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Await(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Yield(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::YieldFrom(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Compare(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Call(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::FormattedValue(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::JoinedStr(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Constant(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Attribute(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Subscript(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Starred(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Name(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::List(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Tuple(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Slice(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprBoolOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.op.to_pyo3_ast(py)?, self.values.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprNamedExpr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.target.to_pyo3_ast(py)?, self.value.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprBinOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.left.to_pyo3_ast(py)?, + self.op.to_pyo3_ast(py)?, + self.right.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprUnaryOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.op.to_pyo3_ast(py)?, self.operand.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprLambda { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.args.to_pyo3_ast(py)?, self.body.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprIfExp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprDict { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.keys.to_pyo3_ast(py)?, self.values.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSet { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.elts.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprListComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSetComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprDictComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.key.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.generators.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprGeneratorExp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprAwait { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprYield { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprYieldFrom { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprCompare { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.left.to_pyo3_ast(py)?, + self.ops.to_pyo3_ast(py)?, + self.comparators.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprCall { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.func.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.keywords.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprFormattedValue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.conversion.to_pyo3_ast(py)?, + self.format_spec.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprJoinedStr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.values.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprConstant { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.value.to_pyo3_ast(py)?, self.kind.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprAttribute { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.attr.to_pyo3_ast(py)?, + self.ctx.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSubscript { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.slice.to_pyo3_ast(py)?, + self.ctx.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprStarred { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.value.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprName { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.id.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprList { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.elts.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprTuple { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.elts.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSlice { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.lower.to_pyo3_ast(py)?, + self.upper.to_pyo3_ast(py)?, + self.step.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Comprehension { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.ifs.to_pyo3_ast(py)?, + self.is_async.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Excepthandler { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Excepthandler::ExceptHandler(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExcepthandlerExceptHandler { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.type_.to_pyo3_ast(py)?, + self.name.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Arguments { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.posonlyargs.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.vararg.to_pyo3_ast(py)?, + self.kwonlyargs.to_pyo3_ast(py)?, + self.kw_defaults.to_pyo3_ast(py)?, + self.kwarg.to_pyo3_ast(py)?, + self.defaults.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Arg { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.arg.to_pyo3_ast(py)?, + self.annotation.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Keyword { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.arg.to_pyo3_ast(py)?, self.value.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Alias { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.name.to_pyo3_ast(py)?, self.asname.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Withitem { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.context_expr.to_pyo3_ast(py)?, + self.optional_vars.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::MatchCase { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.pattern.to_pyo3_ast(py)?, + self.guard.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Pattern { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Pattern::MatchValue(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchSingleton(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchSequence(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchMapping(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchClass(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchStar(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchAs(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchOr(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchValue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchSingleton { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchSequence { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.patterns.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchMapping { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.keys.to_pyo3_ast(py)?, + self.patterns.to_pyo3_ast(py)?, + self.rest.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchClass { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.cls.to_pyo3_ast(py)?, + self.patterns.to_pyo3_ast(py)?, + self.kwd_attrs.to_pyo3_ast(py)?, + self.kwd_patterns.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchStar { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.name.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchAs { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.pattern.to_pyo3_ast(py)?, self.name.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchOr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.patterns.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::TypeIgnore { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::TypeIgnore::TypeIgnore(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::TypeIgnoreTypeIgnore { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.lineno.to_pyo3_ast(py)?, self.tag.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Mod { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Mod::Module(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::Interactive(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::Expression(cons) => cons.to_pyo3_ast(py)?, + crate::Mod::FunctionType(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModModule { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.type_ignores.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModInteractive { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.body.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModExpression { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.body.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ModFunctionType { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.argtypes.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Stmt { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Stmt::FunctionDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncFunctionDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::ClassDef(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Return(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Delete(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Assign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AugAssign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AnnAssign(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::For(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncFor(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::While(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::If(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::With(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::AsyncWith(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Match(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Raise(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Try(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::TryStar(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Assert(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Import(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::ImportFrom(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Global(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Nonlocal(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Expr(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Pass(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Break(cons) => cons.to_pyo3_ast(py)?, + crate::Stmt::Continue(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtFunctionDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncFunctionDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + self.returns.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtClassDef { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.name.to_pyo3_ast(py)?, + self.bases.to_pyo3_ast(py)?, + self.keywords.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.decorator_list.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtReturn { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtDelete { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.targets.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.targets.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAugAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.op.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAnnAssign { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.annotation.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.simple.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtFor { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncFor { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtWhile { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtIf { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtWith { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.items.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAsyncWith { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.items.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtMatch { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.subject.to_pyo3_ast(py)?, self.cases.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtRaise { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.exc.to_pyo3_ast(py)?, self.cause.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtTry { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.handlers.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.finalbody.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtTryStar { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.body.to_pyo3_ast(py)?, + self.handlers.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + self.finalbody.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtAssert { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.test.to_pyo3_ast(py)?, self.msg.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtImport { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtImportFrom { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.module.to_pyo3_ast(py)?, + self.names.to_pyo3_ast(py)?, + self.level.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtGlobal { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtNonlocal { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.names.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtExpr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtPass { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtBreak { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::StmtContinue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call0(py)?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Expr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Expr::BoolOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::NamedExpr(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::BinOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::UnaryOp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Lambda(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::IfExp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Dict(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Set(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::ListComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::SetComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::DictComp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::GeneratorExp(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Await(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Yield(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::YieldFrom(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Compare(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Call(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::FormattedValue(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::JoinedStr(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Constant(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Attribute(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Subscript(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Starred(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Name(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::List(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Tuple(cons) => cons.to_pyo3_ast(py)?, + crate::Expr::Slice(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprBoolOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.op.to_pyo3_ast(py)?, self.values.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprNamedExpr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.target.to_pyo3_ast(py)?, self.value.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprBinOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.left.to_pyo3_ast(py)?, + self.op.to_pyo3_ast(py)?, + self.right.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprUnaryOp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.op.to_pyo3_ast(py)?, self.operand.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprLambda { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.args.to_pyo3_ast(py)?, self.body.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprIfExp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.test.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + self.orelse.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprDict { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.keys.to_pyo3_ast(py)?, self.values.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSet { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.elts.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprListComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSetComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprDictComp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.key.to_pyo3_ast(py)?, + self.value.to_pyo3_ast(py)?, + self.generators.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprGeneratorExp { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.elt.to_pyo3_ast(py)?, self.generators.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprAwait { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprYield { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprYieldFrom { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprCompare { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.left.to_pyo3_ast(py)?, + self.ops.to_pyo3_ast(py)?, + self.comparators.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprCall { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.func.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.keywords.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprFormattedValue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.conversion.to_pyo3_ast(py)?, + self.format_spec.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprJoinedStr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.values.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprConstant { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.value.to_pyo3_ast(py)?, self.kind.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprAttribute { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.attr.to_pyo3_ast(py)?, + self.ctx.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSubscript { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.value.to_pyo3_ast(py)?, + self.slice.to_pyo3_ast(py)?, + self.ctx.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprStarred { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.value.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprName { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.id.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprList { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.elts.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprTuple { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.elts.to_pyo3_ast(py)?, self.ctx.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExprSlice { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.lower.to_pyo3_ast(py)?, + self.upper.to_pyo3_ast(py)?, + self.step.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Comprehension { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.target.to_pyo3_ast(py)?, + self.iter.to_pyo3_ast(py)?, + self.ifs.to_pyo3_ast(py)?, + self.is_async.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Excepthandler { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Excepthandler::ExceptHandler(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::ExcepthandlerExceptHandler { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.type_.to_pyo3_ast(py)?, + self.name.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Arguments { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.posonlyargs.to_pyo3_ast(py)?, + self.args.to_pyo3_ast(py)?, + self.vararg.to_pyo3_ast(py)?, + self.kwonlyargs.to_pyo3_ast(py)?, + self.kw_defaults.to_pyo3_ast(py)?, + self.kwarg.to_pyo3_ast(py)?, + self.defaults.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Arg { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.arg.to_pyo3_ast(py)?, + self.annotation.to_pyo3_ast(py)?, + self.type_comment.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Keyword { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache + .0 + .call1(py, (self.arg.to_pyo3_ast(py)?, self.value.to_pyo3_ast(py)?))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Alias { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.name.to_pyo3_ast(py)?, self.asname.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::Withitem { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.context_expr.to_pyo3_ast(py)?, + self.optional_vars.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::MatchCase { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.pattern.to_pyo3_ast(py)?, + self.guard.to_pyo3_ast(py)?, + self.body.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::Pattern { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::Pattern::MatchValue(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchSingleton(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchSequence(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchMapping(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchClass(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchStar(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchAs(cons) => cons.to_pyo3_ast(py)?, + crate::Pattern::MatchOr(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchValue { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchSingleton { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.value.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchSequence { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.patterns.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchMapping { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.keys.to_pyo3_ast(py)?, + self.patterns.to_pyo3_ast(py)?, + self.rest.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchClass { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + ( + self.cls.to_pyo3_ast(py)?, + self.patterns.to_pyo3_ast(py)?, + self.kwd_attrs.to_pyo3_ast(py)?, + self.kwd_patterns.to_pyo3_ast(py)?, + ), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchStar { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.name.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchAs { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.pattern.to_pyo3_ast(py)?, self.name.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::PatternMatchOr { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1(py, (self.patterns.to_pyo3_ast(py)?,))?; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::generic::TypeIgnore { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let instance = match &self { + crate::TypeIgnore::TypeIgnore(cons) => cons.to_pyo3_ast(py)?, + }; + Ok(instance) + } +} + +impl ToPyo3Ast for crate::TypeIgnoreTypeIgnore { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let cache = Self::py_type_cache().get().unwrap(); + let instance = cache.0.call1( + py, + (self.lineno.to_pyo3_ast(py)?, self.tag.to_pyo3_ast(py)?), + )?; + Ok(instance) + } +} + +pub fn init(py: Python) -> PyResult<()> { + let ast_module = PyModule::import(py, "_ast")?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + cache_py_type::(ast_module)?; + Ok(()) +} diff --git a/ast/src/lib.rs b/ast/src/lib.rs index d1f63d1ec3..814650ef6c 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -47,3 +47,6 @@ pub use visitor::Visitor; mod optimizer; #[cfg(feature = "constant-optimization")] pub use optimizer::ConstantOptimizer; + +#[cfg(feature = "pyo3")] +pub mod pyo3; diff --git a/ast/src/pyo3.rs b/ast/src/pyo3.rs new file mode 100644 index 0000000000..d54a59e6fb --- /dev/null +++ b/ast/src/pyo3.rs @@ -0,0 +1,116 @@ +use crate::{source_code::SourceRange, text_size::TextRange, Node}; +use num_complex::Complex64; +use once_cell::sync::OnceCell; +use pyo3::prelude::*; +use pyo3::types::{PyBytes, PyList, PyTuple}; + +pub trait Pyo3Node { + fn py_type_cache() -> &'static OnceCell<(Py, Py)> { + { + static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); + &PY_TYPE + } + } +} + +pub trait ToPyo3Ast { + fn to_pyo3_ast(&self, py: Python) -> PyResult>; +} + +impl ToPyo3Ast for Box { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + (**self).to_pyo3_ast(py) + } +} + +impl ToPyo3Ast for Option { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + match self { + Some(ast) => ast.to_pyo3_ast(py), + None => Ok(py.None()), + } + } +} + +impl ToPyo3Ast for Vec { + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let list = PyList::empty(py); + for item in self { + let py_item = item.to_pyo3_ast(py)?; + list.append(py_item)?; + } + Ok(list.into()) + } +} + +impl ToPyo3Ast for crate::Identifier { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + Ok(self.as_str().to_object(py)) + } +} + +impl ToPyo3Ast for crate::String { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + Ok(self.as_str().to_object(py)) + } +} + +impl ToPyo3Ast for crate::Int { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + Ok((self.to_u32()).to_object(py)) + } +} + +impl ToPyo3Ast for bool { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + Ok((*self as u32).to_object(py)) + } +} + +impl ToPyo3Ast for crate::Constant { + #[inline] + fn to_pyo3_ast(&self, py: Python) -> PyResult> { + let value = match self { + crate::Constant::None => py.None(), + crate::Constant::Bool(bool) => bool.to_object(py), + crate::Constant::Str(string) => string.to_object(py), + crate::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(), + crate::Constant::Int(int) => int.to_object(py), + crate::Constant::Tuple(elts) => { + let elts: PyResult> = elts.iter().map(|c| c.to_pyo3_ast(py)).collect(); + PyTuple::new(py, elts?).into() + } + crate::Constant::Float(f64) => f64.to_object(py), + crate::Constant::Complex { real, imag } => Complex64::new(*real, *imag).to_object(py), + crate::Constant::Ellipsis => py.Ellipsis(), + }; + Ok(value) + } +} + +#[pyclass(module = "rustpython_ast", subclass)] +pub struct AST; + +#[pymethods] +impl AST { + #[new] + fn new() -> Self { + Self + } +} + +fn cache_py_type(ast_module: &PyAny) -> PyResult<()> { + let class = ast_module.getattr(N::NAME).unwrap(); + let base = class.getattr("__new__").unwrap(); + N::py_type_cache().get_or_init(|| (class.into(), base.into())); + + Ok(()) +} + +include!("gen/to_pyo3.rs");