Skip to content

Commit d6242ac

Browse files
committed
Use py_module macro on ast module.
1 parent f2e60b2 commit d6242ac

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

vm/src/stdlib/ast.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,23 +602,10 @@ fn ast_parse(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
602602
}
603603

604604
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
605-
// TODO: maybe we can use some clever macro to generate this?
606-
let ast_mod = ctx.new_module("ast", ctx.new_scope(None));
607-
608-
ctx.set_attr(&ast_mod, "parse", ctx.new_rustfunc(ast_parse));
609-
610-
ctx.set_attr(
611-
&ast_mod,
612-
"Module",
613-
ctx.new_class("_ast.Module", ctx.object()),
614-
);
615-
616-
ctx.set_attr(
617-
&ast_mod,
618-
"FunctionDef",
619-
ctx.new_class("_ast.FunctionDef", ctx.object()),
620-
);
621-
ctx.set_attr(&ast_mod, "Call", ctx.new_class("_ast.Call", ctx.object()));
622-
623-
ast_mod
605+
py_module!(ctx, "ast", {
606+
"parse" => ctx.new_rustfunc(ast_parse),
607+
"Module" => ctx.new_class("_ast.Module", ctx.object()),
608+
"FunctionDef" =>ctx.new_class("_ast.FunctionDef", ctx.object()),
609+
"Call" => ctx.new_class("_ast.Call", ctx.object())
610+
})
624611
}

0 commit comments

Comments
 (0)