MCPcopy Index your code
hub / github.com/RustPython/RustPython / ast_from_object

Method ast_from_object

crates/vm/src/stdlib/_ast/module.rs:38–62  ·  view source on GitHub ↗
(
        vm: &VirtualMachine,
        source_file: &SourceFile,
        object: PyObjectRef,
    )

Source from the content-addressed store, hash-verified

36 }
37
38 fn ast_from_object(
39 vm: &VirtualMachine,
40 source_file: &SourceFile,
41 object: PyObjectRef,
42 ) -> PyResult<Self> {
43 let cls = object.class();
44 Ok(if cls.is(pyast::NodeModModule::static_type()) {
45 Self::Module(ast::ModModule::ast_from_object(vm, source_file, object)?)
46 } else if cls.is(pyast::NodeModInteractive::static_type()) {
47 Self::Interactive(ModInteractive::ast_from_object(vm, source_file, object)?)
48 } else if cls.is(pyast::NodeModExpression::static_type()) {
49 Self::Expression(ast::ModExpression::ast_from_object(
50 vm,
51 source_file,
52 object,
53 )?)
54 } else if cls.is(pyast::NodeModFunctionType::static_type()) {
55 Self::FunctionType(ModFunctionType::ast_from_object(vm, source_file, object)?)
56 } else {
57 return Err(vm.new_type_error(format!(
58 "expected some sort of mod, but got {}",
59 object.repr(vm)?
60 )));
61 })
62 }
63}
64
65// constructor

Callers

nothing calls this directly

Calls 7

ast_from_objectFunction · 0.85
FunctionTypeFunction · 0.85
get_node_fieldFunction · 0.85
isMethod · 0.80
ModuleClass · 0.50
ErrClass · 0.50
classMethod · 0.45

Tested by

no test coverage detected