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

Method ast_from_object

crates/vm/src/stdlib/_ast/statement.rs:40–144  ·  view source on GitHub ↗
(
        _vm: &VirtualMachine,
        source_file: &SourceFile,
        _object: PyObjectRef,
    )

Source from the content-addressed store, hash-verified

38
39 #[allow(clippy::if_same_then_else)]
40 fn ast_from_object(
41 _vm: &VirtualMachine,
42 source_file: &SourceFile,
43 _object: PyObjectRef,
44 ) -> PyResult<Self> {
45 let _cls = _object.class();
46 Ok(if _cls.is(pyast::NodeStmtFunctionDef::static_type()) {
47 Self::FunctionDef(ast::StmtFunctionDef::ast_from_object(
48 _vm,
49 source_file,
50 _object,
51 )?)
52 } else if _cls.is(pyast::NodeStmtAsyncFunctionDef::static_type()) {
53 Self::FunctionDef(ast::StmtFunctionDef::ast_from_object(
54 _vm,
55 source_file,
56 _object,
57 )?)
58 } else if _cls.is(pyast::NodeStmtClassDef::static_type()) {
59 Self::ClassDef(ast::StmtClassDef::ast_from_object(
60 _vm,
61 source_file,
62 _object,
63 )?)
64 } else if _cls.is(pyast::NodeStmtReturn::static_type()) {
65 Self::Return(ast::StmtReturn::ast_from_object(_vm, source_file, _object)?)
66 } else if _cls.is(pyast::NodeStmtDelete::static_type()) {
67 Self::Delete(ast::StmtDelete::ast_from_object(_vm, source_file, _object)?)
68 } else if _cls.is(pyast::NodeStmtAssign::static_type()) {
69 Self::Assign(ast::StmtAssign::ast_from_object(_vm, source_file, _object)?)
70 } else if _cls.is(pyast::NodeStmtTypeAlias::static_type()) {
71 Self::TypeAlias(ast::StmtTypeAlias::ast_from_object(
72 _vm,
73 source_file,
74 _object,
75 )?)
76 } else if _cls.is(pyast::NodeStmtAugAssign::static_type()) {
77 Self::AugAssign(ast::StmtAugAssign::ast_from_object(
78 _vm,
79 source_file,
80 _object,
81 )?)
82 } else if _cls.is(pyast::NodeStmtAnnAssign::static_type()) {
83 Self::AnnAssign(ast::StmtAnnAssign::ast_from_object(
84 _vm,
85 source_file,
86 _object,
87 )?)
88 } else if _cls.is(pyast::NodeStmtFor::static_type()) {
89 Self::For(ast::StmtFor::ast_from_object(_vm, source_file, _object)?)
90 } else if _cls.is(pyast::NodeStmtAsyncFor::static_type()) {
91 Self::For(ast::StmtFor::ast_from_object(_vm, source_file, _object)?)
92 } else if _cls.is(pyast::NodeStmtWhile::static_type()) {
93 Self::While(ast::StmtWhile::ast_from_object(_vm, source_file, _object)?)
94 } else if _cls.is(pyast::NodeStmtIf::static_type()) {
95 Self::If(ast::StmtIf::ast_from_object(_vm, source_file, _object)?)
96 } else if _cls.is(pyast::NodeStmtWith::static_type()) {
97 Self::With(ast::StmtWith::ast_from_object(_vm, source_file, _object)?)

Callers

nothing calls this directly

Calls 15

ast_from_objectFunction · 0.85
TypeAliasFunction · 0.85
MatchClass · 0.85
BreakClass · 0.85
range_from_objectFunction · 0.85
get_node_fieldFunction · 0.85
get_node_field_optFunction · 0.85
newFunction · 0.85
merge_class_def_argsFunction · 0.85
isMethod · 0.80
new_listMethod · 0.80
noneMethod · 0.80

Tested by

no test coverage detected