(
vm: &VirtualMachine,
module: &Py<crate::builtins::PyModule>,
)
| 441 | use super::PY_CF_OPTIMIZED_AST; |
| 442 | |
| 443 | pub(crate) fn module_exec( |
| 444 | vm: &VirtualMachine, |
| 445 | module: &Py<crate::builtins::PyModule>, |
| 446 | ) -> PyResult<()> { |
| 447 | __module_exec(vm, module); |
| 448 | super::super::pyast::extend_module_nodes(vm, module); |
| 449 | |
| 450 | let ast_type = module |
| 451 | .get_attr("AST", vm)? |
| 452 | .downcast::<PyType>() |
| 453 | .map_err(|_| vm.new_type_error("AST is not a type"))?; |
| 454 | let ctx = &vm.ctx; |
| 455 | let empty_tuple = ctx.empty_tuple.clone(); |
| 456 | ast_type.set_str_attr("_fields", empty_tuple.clone(), ctx); |
| 457 | ast_type.set_str_attr("_attributes", empty_tuple.clone(), ctx); |
| 458 | ast_type.set_str_attr("__match_args__", empty_tuple.clone(), ctx); |
| 459 | |
| 460 | const AST_REDUCE: PyMethodDef = PyMethodDef::new_const( |
| 461 | "__reduce__", |
| 462 | |zelf: PyObjectRef, vm: &VirtualMachine| -> PyResult<PyTupleRef> { |
| 463 | ast_reduce(zelf, vm) |
| 464 | }, |
| 465 | PyMethodFlags::METHOD, |
| 466 | None, |
| 467 | ); |
| 468 | const AST_REPLACE: PyMethodDef = PyMethodDef::new_const( |
| 469 | "__replace__", |
| 470 | |zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine| -> PyResult { |
| 471 | ast_replace(zelf, args, vm) |
| 472 | }, |
| 473 | PyMethodFlags::METHOD, |
| 474 | None, |
| 475 | ); |
| 476 | let base_type = NodeAst::static_type(); |
| 477 | ast_type.set_str_attr( |
| 478 | "__reduce__", |
| 479 | AST_REDUCE.to_proper_method(base_type, ctx), |
| 480 | ctx, |
| 481 | ); |
| 482 | ast_type.set_str_attr( |
| 483 | "__replace__", |
| 484 | AST_REPLACE.to_proper_method(base_type, ctx), |
| 485 | ctx, |
| 486 | ); |
| 487 | ast_type.slots.repr.store(Some(ast_repr)); |
| 488 | |
| 489 | const EXPR_DOC: &str = "expr = BoolOp(boolop op, expr* values)\n\ |
| 490 | | NamedExpr(expr target, expr value)\n\ |
| 491 | | BinOp(expr left, operator op, expr right)\n\ |
| 492 | | UnaryOp(unaryop op, expr operand)\n\ |
| 493 | | Lambda(arguments args, expr body)\n\ |
| 494 | | IfExp(expr test, expr body, expr orelse)\n\ |
| 495 | | Dict(expr?* keys, expr* values)\n\ |
| 496 | | Set(expr* elts)\n\ |
| 497 | | ListComp(expr elt, comprehension* generators)\n\ |
| 498 | | SetComp(expr elt, comprehension* generators)\n\ |
| 499 | | DictComp(expr key, expr value, comprehension* generators)\n\ |
| 500 | | GeneratorExp(expr elt, comprehension* generators)\n\ |
nothing calls this directly
no test coverage detected