Skip to content

Commit 3c1ab2d

Browse files
authored
Add RustPython runtime AST fields (#2)
1 parent 32d9059 commit 3c1ab2d

608 files changed

Lines changed: 9630 additions & 522 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/ruff_python_ast/ast.toml

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ doc = "See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)"
6767

6868
[Mod.nodes.ModModule]
6969
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
70-
fields = [{ name = "body", type = "Stmt*" }]
70+
fields = [
71+
{ name = "body", type = "Stmt*" },
72+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
73+
]
7174

7275
[Mod.nodes.ModExpression]
7376
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
@@ -91,6 +94,10 @@ fields = [
9194
{ name = "parameters", type = "Box<crate::Parameters>" },
9295
{ name = "returns", type = "Expr?", is_annotation = true },
9396
{ name = "body", type = "Stmt*" },
97+
{ name = "runtime_decorator_list", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
98+
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
99+
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
100+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
94101
]
95102

96103
[Stmt.nodes.StmtClassDef]
@@ -101,6 +108,8 @@ fields = [
101108
{ name = "type_params", type = "Box<crate::TypeParams>?" },
102109
{ name = "arguments", type = "Box<crate::Arguments>?" },
103110
{ name = "body", type = "Stmt*" },
111+
{ name = "runtime_decorator_list", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
112+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
104113
]
105114

106115
[Stmt.nodes.StmtReturn]
@@ -109,7 +118,10 @@ fields = [{ name = "value", type = "Expr?" }]
109118

110119
[Stmt.nodes.StmtDelete]
111120
doc = "See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete)"
112-
fields = [{ name = "targets", type = "Expr*" }]
121+
fields = [
122+
{ name = "targets", type = "Expr*" },
123+
{ name = "runtime_targets", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
124+
]
113125

114126
[Stmt.nodes.StmtTypeAlias]
115127
doc = "See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias)"
@@ -124,6 +136,9 @@ doc = "See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign)"
124136
fields = [
125137
{ name = "targets", type = "Expr*" },
126138
{ name = "value", type = "Expr" },
139+
{ name = "runtime_targets", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
140+
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
141+
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
127142
]
128143

129144
[Stmt.nodes.StmtAugAssign]
@@ -141,6 +156,7 @@ fields = [
141156
{ name = "annotation", type = "Expr", is_annotation = true },
142157
{ name = "value", type = "Expr?" },
143158
{ name = "simple", type = "bool" },
159+
{ name = "runtime_simple", type = "i32?", skip_visit = true },
144160
]
145161

146162
[Stmt.nodes.StmtFor]
@@ -154,6 +170,10 @@ fields = [
154170
{ name = "iter", type = "Expr" },
155171
{ name = "body", type = "Stmt*" },
156172
{ name = "orelse", type = "Stmt*" },
173+
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
174+
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
175+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
176+
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
157177
]
158178

159179
[Stmt.nodes.StmtWhile]
@@ -163,6 +183,8 @@ fields = [
163183
{ name = "test", type = "Expr" },
164184
{ name = "body", type = "Stmt*" },
165185
{ name = "orelse", type = "Stmt*" },
186+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
187+
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
166188
]
167189

168190
[Stmt.nodes.StmtIf]
@@ -172,6 +194,7 @@ fields = [
172194
{ name = "test", type = "Expr" },
173195
{ name = "body", type = "Stmt*" },
174196
{ name = "elif_else_clauses", type = "ElifElseClause*" },
197+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
175198
]
176199

177200
[Stmt.nodes.StmtWith]
@@ -183,6 +206,9 @@ fields = [
183206
{ name = "is_async", type = "bool" },
184207
{ name = "items", type = "WithItem*" },
185208
{ name = "body", type = "Stmt*" },
209+
{ name = "runtime_type_comment", type = "Box<str>?", skip_visit = true },
210+
{ name = "runtime_type_comment_bytes", type = "Vec<u8>?", skip_visit = true },
211+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
186212
]
187213

188214
[Stmt.nodes.StmtMatch]
@@ -205,6 +231,10 @@ fields = [
205231
{ name = "orelse", type = "Stmt*" },
206232
{ name = "finalbody", type = "Stmt*" },
207233
{ name = "is_star", type = "bool" },
234+
{ name = "runtime_body", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
235+
{ name = "runtime_handlers", type = "Vec<Option<crate::ExceptHandler>>?", skip_visit = true },
236+
{ name = "runtime_orelse", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
237+
{ name = "runtime_finalbody", type = "Vec<Option<crate::Stmt>>?", skip_visit = true },
208238
]
209239

210240
[Stmt.nodes.StmtAssert]
@@ -225,6 +255,7 @@ fields = [
225255
{ name = "names", type = "Alias*" },
226256
{ name = "level", type = "u32" },
227257
{ name = "is_lazy", type = "bool" },
258+
{ name = "runtime_level", type = "i32?", skip_visit = true },
228259
]
229260

230261
[Stmt.nodes.StmtGlobal]
@@ -319,7 +350,11 @@ doc = "See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)"
319350

320351
[Expr.nodes.ExprBoolOp]
321352
doc = "See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp)"
322-
fields = [{ name = "op", type = "BoolOp" }, { name = "values", type = "Expr*" }]
353+
fields = [
354+
{ name = "op", type = "BoolOp" },
355+
{ name = "values", type = "Expr*" },
356+
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
357+
]
323358
custom_source_order = true
324359

325360
[Expr.nodes.ExprNamed]
@@ -359,12 +394,18 @@ source_order = ["body", "test", "orelse"]
359394

360395
[Expr.nodes.ExprDict]
361396
doc = "See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict)"
362-
fields = [{ name = "items", type = "DictItem*" }]
397+
fields = [
398+
{ name = "items", type = "DictItem*" },
399+
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
400+
]
363401
custom_source_order = true
364402

365403
[Expr.nodes.ExprSet]
366404
doc = "See also [Set](https://docs.python.org/3/library/ast.html#ast.Set)"
367-
fields = [{ name = "elts", type = "Expr*" }]
405+
fields = [
406+
{ name = "elts", type = "Expr*" },
407+
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
408+
]
368409

369410
[Expr.nodes.ExprListComp]
370411
doc = "See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp)"
@@ -414,6 +455,7 @@ fields = [
414455
{ name = "left", type = "Expr" },
415456
{ name = "ops", type = "&CmpOp*" },
416457
{ name = "comparators", type = "&Expr*" },
458+
{ name = "runtime_comparators", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
417459
]
418460
# The fields must be visited simultaneously
419461
custom_source_order = true
@@ -434,7 +476,11 @@ doesn't join the implicitly concatenated parts into a single string. Instead,
434476
it keeps them separate and provide various methods to access the parts.
435477
436478
See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)"""
437-
fields = [{ name = "value", type = "FStringValue" }]
479+
fields = [
480+
{ name = "value", type = "FStringValue" },
481+
{ name = "runtime_joined_str", type = "Vec<crate::Expr>?", skip_visit = true },
482+
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
483+
]
438484
custom_source_order = true
439485

440486
[Expr.nodes.ExprTString]
@@ -446,7 +492,11 @@ doesn't join the implicitly concatenated parts into a single string. Instead,
446492
it keeps them separate and provide various methods to access the parts.
447493
448494
See also [TemplateStr](https://docs.python.org/3/library/ast.html#ast.TemplateStr)"""
449-
fields = [{ name = "value", type = "TStringValue" }]
495+
fields = [
496+
{ name = "value", type = "TStringValue" },
497+
{ name = "runtime_template_str", type = "Vec<crate::Expr>?", skip_visit = true },
498+
{ name = "runtime_values", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
499+
]
450500
custom_source_order = true
451501

452502
[Expr.nodes.ExprStringLiteral]
@@ -475,9 +525,18 @@ fields = []
475525
derives = ["Default"]
476526

477527
[Expr.nodes.ExprEllipsisLiteral]
478-
fields = []
528+
fields = [
529+
]
479530
derives = ["Default"]
480531

532+
[Expr.nodes.ExprConstant]
533+
doc = "See also [Constant](https://docs.python.org/3/library/ast.html#ast.Constant)"
534+
fields = [
535+
{ name = "value", type = "ConstantValue", skip_visit = true },
536+
{ name = "kind", type = "Box<str>?", skip_visit = true },
537+
{ name = "invalid_type", type = "Box<str>?", skip_visit = true },
538+
]
539+
481540
[Expr.nodes.ExprAttribute]
482541
doc = "See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute)"
483542
fields = [
@@ -513,6 +572,7 @@ doc = "See also [List](https://docs.python.org/3/library/ast.html#ast.List)"
513572
fields = [
514573
{ name = "elts", type = "Expr*" },
515574
{ name = "ctx", type = "ExprContext" },
575+
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
516576
]
517577

518578
[Expr.nodes.ExprTuple]
@@ -521,6 +581,7 @@ fields = [
521581
{ name = "elts", type = "Expr*" },
522582
{ name = "ctx", type = "ExprContext" },
523583
{ name = "parenthesized", type = "bool" },
584+
{ name = "runtime_elts", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
524585
]
525586

526587
[Expr.nodes.ExprSlice]
@@ -573,14 +634,19 @@ fields = [{ name = "value", type = "Singleton" }]
573634

574635
[Pattern.nodes.PatternMatchSequence]
575636
doc = "See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence)"
576-
fields = [{ name = "patterns", type = "Pattern*" }]
637+
fields = [
638+
{ name = "patterns", type = "Pattern*" },
639+
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
640+
]
577641

578642
[Pattern.nodes.PatternMatchMapping]
579643
doc = "See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping)"
580644
fields = [
581645
{ name = "keys", type = "Expr*" },
582646
{ name = "patterns", type = "Pattern*" },
583647
{ name = "rest", type = "Identifier?" },
648+
{ name = "runtime_keys", type = "Vec<Option<crate::Expr>>?", skip_visit = true },
649+
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
584650
]
585651
custom_source_order = true
586652

@@ -589,6 +655,9 @@ doc = "See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.Matc
589655
fields = [
590656
{ name = "cls", type = "Box<Expr>" },
591657
{ name = "arguments", type = "PatternArguments" },
658+
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
659+
{ name = "runtime_kwd_attrs", type = "Vec<crate::Identifier>?", skip_visit = true },
660+
{ name = "runtime_kwd_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
592661
]
593662

594663
[Pattern.nodes.PatternMatchStar]
@@ -604,7 +673,10 @@ fields = [
604673

605674
[Pattern.nodes.PatternMatchOr]
606675
doc = "See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr)"
607-
fields = [{ name = "patterns", type = "Pattern*" }]
676+
fields = [
677+
{ name = "patterns", type = "Pattern*" },
678+
{ name = "runtime_patterns", type = "Vec<Option<crate::Pattern>>?", skip_visit = true },
679+
]
608680

609681
[TypeParam]
610682
doc = "See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)"

crates/ruff_python_ast/generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"Alias",
4141
"Singleton",
4242
"PatternArguments",
43+
"ConstantValue",
4344
}
4445

4546

0 commit comments

Comments
 (0)