@@ -36,111 +36,99 @@ impl Node for ast::Stmt {
3636 }
3737 }
3838
39- #[ allow ( clippy:: if_same_then_else) ]
39+ #[ expect ( clippy:: if_same_then_else, reason = "Looks better here" ) ]
4040 fn ast_from_object (
41- _vm : & VirtualMachine ,
41+ vm : & VirtualMachine ,
4242 source_file : & SourceFile ,
43- _object : PyObjectRef ,
43+ object : PyObjectRef ,
4444 ) -> PyResult < Self > {
45- let _cls = _object . class ( ) ;
46- Ok ( if _cls . is ( pyast:: NodeStmtFunctionDef :: static_type ( ) ) {
45+ let cls = object . class ( ) ;
46+ Ok ( if cls . is ( pyast:: NodeStmtFunctionDef :: static_type ( ) ) {
4747 Self :: FunctionDef ( ast:: StmtFunctionDef :: ast_from_object (
48- _vm ,
48+ vm ,
4949 source_file,
50- _object ,
50+ object ,
5151 ) ?)
52- } else if _cls . is ( pyast:: NodeStmtAsyncFunctionDef :: static_type ( ) ) {
52+ } else if cls . is ( pyast:: NodeStmtAsyncFunctionDef :: static_type ( ) ) {
5353 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,
54+ vm,
6155 source_file,
62- _object ,
56+ object ,
6357 ) ?)
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 ( ) ) {
58+ } else if cls. is ( pyast:: NodeStmtClassDef :: static_type ( ) ) {
59+ Self :: ClassDef ( ast:: StmtClassDef :: ast_from_object ( vm, source_file, object) ?)
60+ } else if cls. is ( pyast:: NodeStmtReturn :: static_type ( ) ) {
61+ Self :: Return ( ast:: StmtReturn :: ast_from_object ( vm, source_file, object) ?)
62+ } else if cls. is ( pyast:: NodeStmtDelete :: static_type ( ) ) {
63+ Self :: Delete ( ast:: StmtDelete :: ast_from_object ( vm, source_file, object) ?)
64+ } else if cls. is ( pyast:: NodeStmtAssign :: static_type ( ) ) {
65+ Self :: Assign ( ast:: StmtAssign :: ast_from_object ( vm, source_file, object) ?)
66+ } else if cls. is ( pyast:: NodeStmtTypeAlias :: static_type ( ) ) {
7167 Self :: TypeAlias ( ast:: StmtTypeAlias :: ast_from_object (
72- _vm ,
68+ vm ,
7369 source_file,
74- _object ,
70+ object ,
7571 ) ?)
76- } else if _cls . is ( pyast:: NodeStmtAugAssign :: static_type ( ) ) {
72+ } else if cls . is ( pyast:: NodeStmtAugAssign :: static_type ( ) ) {
7773 Self :: AugAssign ( ast:: StmtAugAssign :: ast_from_object (
78- _vm ,
74+ vm ,
7975 source_file,
80- _object ,
76+ object ,
8177 ) ?)
82- } else if _cls . is ( pyast:: NodeStmtAnnAssign :: static_type ( ) ) {
78+ } else if cls . is ( pyast:: NodeStmtAnnAssign :: static_type ( ) ) {
8379 Self :: AnnAssign ( ast:: StmtAnnAssign :: ast_from_object (
84- _vm ,
80+ vm ,
8581 source_file,
86- _object ,
82+ object ,
8783 ) ?)
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 ) ?)
98- } else if _cls . is ( pyast:: NodeStmtAsyncWith :: static_type ( ) ) {
99- Self :: With ( ast:: StmtWith :: ast_from_object ( _vm , source_file, _object ) ?)
100- } else if _cls . is ( pyast:: NodeStmtMatch :: static_type ( ) ) {
101- Self :: Match ( ast:: StmtMatch :: ast_from_object ( _vm , source_file, _object ) ?)
102- } else if _cls . is ( pyast:: NodeStmtRaise :: static_type ( ) ) {
103- Self :: Raise ( ast:: StmtRaise :: ast_from_object ( _vm , source_file, _object ) ?)
104- } else if _cls . is ( pyast:: NodeStmtTry :: static_type ( ) ) {
105- Self :: Try ( ast:: StmtTry :: ast_from_object ( _vm , source_file, _object ) ?)
106- } else if _cls . is ( pyast:: NodeStmtTryStar :: static_type ( ) ) {
107- Self :: Try ( ast:: StmtTry :: ast_from_object ( _vm , source_file, _object ) ?)
108- } else if _cls . is ( pyast:: NodeStmtAssert :: static_type ( ) ) {
109- Self :: Assert ( ast:: StmtAssert :: ast_from_object ( _vm , source_file, _object ) ?)
110- } else if _cls . is ( pyast:: NodeStmtImport :: static_type ( ) ) {
111- Self :: Import ( ast:: StmtImport :: ast_from_object ( _vm , source_file, _object ) ?)
112- } else if _cls . is ( pyast:: NodeStmtImportFrom :: static_type ( ) ) {
84+ } else if cls . is ( pyast:: NodeStmtFor :: static_type ( ) ) {
85+ Self :: For ( ast:: StmtFor :: ast_from_object ( vm , source_file, object ) ?)
86+ } else if cls . is ( pyast:: NodeStmtAsyncFor :: static_type ( ) ) {
87+ Self :: For ( ast:: StmtFor :: ast_from_object ( vm , source_file, object ) ?)
88+ } else if cls . is ( pyast:: NodeStmtWhile :: static_type ( ) ) {
89+ Self :: While ( ast:: StmtWhile :: ast_from_object ( vm , source_file, object ) ?)
90+ } else if cls . is ( pyast:: NodeStmtIf :: static_type ( ) ) {
91+ Self :: If ( ast:: StmtIf :: ast_from_object ( vm , source_file, object ) ?)
92+ } else if cls . is ( pyast:: NodeStmtWith :: static_type ( ) ) {
93+ Self :: With ( ast:: StmtWith :: ast_from_object ( vm , source_file, object ) ?)
94+ } else if cls . is ( pyast:: NodeStmtAsyncWith :: static_type ( ) ) {
95+ Self :: With ( ast:: StmtWith :: ast_from_object ( vm , source_file, object ) ?)
96+ } else if cls . is ( pyast:: NodeStmtMatch :: static_type ( ) ) {
97+ Self :: Match ( ast:: StmtMatch :: ast_from_object ( vm , source_file, object ) ?)
98+ } else if cls . is ( pyast:: NodeStmtRaise :: static_type ( ) ) {
99+ Self :: Raise ( ast:: StmtRaise :: ast_from_object ( vm , source_file, object ) ?)
100+ } else if cls . is ( pyast:: NodeStmtTry :: static_type ( ) ) {
101+ Self :: Try ( ast:: StmtTry :: ast_from_object ( vm , source_file, object ) ?)
102+ } else if cls . is ( pyast:: NodeStmtTryStar :: static_type ( ) ) {
103+ Self :: Try ( ast:: StmtTry :: ast_from_object ( vm , source_file, object ) ?)
104+ } else if cls . is ( pyast:: NodeStmtAssert :: static_type ( ) ) {
105+ Self :: Assert ( ast:: StmtAssert :: ast_from_object ( vm , source_file, object ) ?)
106+ } else if cls . is ( pyast:: NodeStmtImport :: static_type ( ) ) {
107+ Self :: Import ( ast:: StmtImport :: ast_from_object ( vm , source_file, object ) ?)
108+ } else if cls . is ( pyast:: NodeStmtImportFrom :: static_type ( ) ) {
113109 Self :: ImportFrom ( ast:: StmtImportFrom :: ast_from_object (
114- _vm,
115- source_file,
116- _object,
117- ) ?)
118- } else if _cls. is ( pyast:: NodeStmtGlobal :: static_type ( ) ) {
119- Self :: Global ( ast:: StmtGlobal :: ast_from_object ( _vm, source_file, _object) ?)
120- } else if _cls. is ( pyast:: NodeStmtNonlocal :: static_type ( ) ) {
121- Self :: Nonlocal ( ast:: StmtNonlocal :: ast_from_object (
122- _vm,
123- source_file,
124- _object,
125- ) ?)
126- } else if _cls. is ( pyast:: NodeStmtExpr :: static_type ( ) ) {
127- Self :: Expr ( ast:: StmtExpr :: ast_from_object ( _vm, source_file, _object) ?)
128- } else if _cls. is ( pyast:: NodeStmtPass :: static_type ( ) ) {
129- Self :: Pass ( ast:: StmtPass :: ast_from_object ( _vm, source_file, _object) ?)
130- } else if _cls. is ( pyast:: NodeStmtBreak :: static_type ( ) ) {
131- Self :: Break ( ast:: StmtBreak :: ast_from_object ( _vm, source_file, _object) ?)
132- } else if _cls. is ( pyast:: NodeStmtContinue :: static_type ( ) ) {
133- Self :: Continue ( ast:: StmtContinue :: ast_from_object (
134- _vm,
110+ vm,
135111 source_file,
136- _object ,
112+ object ,
137113 ) ?)
138- } else if _vm. is_none ( & _object) {
139- return Err ( _vm. new_value_error ( "None disallowed in statement list" ) ) ;
114+ } else if cls. is ( pyast:: NodeStmtGlobal :: static_type ( ) ) {
115+ Self :: Global ( ast:: StmtGlobal :: ast_from_object ( vm, source_file, object) ?)
116+ } else if cls. is ( pyast:: NodeStmtNonlocal :: static_type ( ) ) {
117+ Self :: Nonlocal ( ast:: StmtNonlocal :: ast_from_object ( vm, source_file, object) ?)
118+ } else if cls. is ( pyast:: NodeStmtExpr :: static_type ( ) ) {
119+ Self :: Expr ( ast:: StmtExpr :: ast_from_object ( vm, source_file, object) ?)
120+ } else if cls. is ( pyast:: NodeStmtPass :: static_type ( ) ) {
121+ Self :: Pass ( ast:: StmtPass :: ast_from_object ( vm, source_file, object) ?)
122+ } else if cls. is ( pyast:: NodeStmtBreak :: static_type ( ) ) {
123+ Self :: Break ( ast:: StmtBreak :: ast_from_object ( vm, source_file, object) ?)
124+ } else if cls. is ( pyast:: NodeStmtContinue :: static_type ( ) ) {
125+ Self :: Continue ( ast:: StmtContinue :: ast_from_object ( vm, source_file, object) ?)
126+ } else if vm. is_none ( & object) {
127+ return Err ( vm. new_value_error ( "None disallowed in statement list" ) ) ;
140128 } else {
141- return Err ( _vm . new_type_error ( format ! (
129+ return Err ( vm . new_type_error ( format ! (
142130 "expected some sort of stmt, but got {}" ,
143- _object . repr( _vm ) ?
131+ object . repr( vm ) ?
144132 ) ) ) ;
145133 } )
146134 }
@@ -201,6 +189,7 @@ impl Node for ast::StmtFunctionDef {
201189 node_add_location ( & dict, range, vm, source_file) ;
202190 node. into ( )
203191 }
192+
204193 fn ast_from_object (
205194 _vm : & VirtualMachine ,
206195 source_file : & SourceFile ,
0 commit comments