Skip to content

Commit 6fa3d0f

Browse files
committed
Fine-tune int types
1 parent 455bcc0 commit 6fa3d0f

15 files changed

+27
-42
lines changed

ast/asdl_rs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@
2424
}
2525
assert builtin_type_mapping.keys() == asdl.builtin_types
2626

27+
builtin_int_mapping = {
28+
"simple": "bool",
29+
"is_async": "bool",
30+
}
2731

2832
def rust_type_name(name):
2933
"""Return a string for the C name of the type.
3034
3135
This function special cases the default types provided by asdl.
3236
"""
3337
if name in asdl.builtin_types:
34-
return builtin_type_mapping[name]
38+
builtin = builtin_type_mapping[name]
39+
return builtin
3540
elif name.islower():
3641
return "".join(part.capitalize() for part in name.split("_"))
3742
else:
@@ -355,6 +360,8 @@ def visitField(self, field, parent, vis, depth, constructor=None):
355360
typ = f"Option<{typ}>"
356361
if field.seq:
357362
typ = f"Vec<{typ}>"
363+
if typ == "Int":
364+
typ = builtin_int_mapping.get(field.name, typ)
358365
name = rust_field(field.name)
359366
self.emit(f"{vis}{name}: {typ},", depth)
360367

ast/src/gen/generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub struct StmtAnnAssign<U = ()> {
154154
pub target: Box<Expr<U>>,
155155
pub annotation: Box<Expr<U>>,
156156
pub value: Option<Box<Expr<U>>>,
157-
pub simple: Int,
157+
pub simple: bool,
158158
}
159159

160160
impl<U> From<StmtAnnAssign<U>> for StmtKind<U> {
@@ -815,7 +815,7 @@ pub struct Comprehension<U = ()> {
815815
pub target: Expr<U>,
816816
pub iter: Expr<U>,
817817
pub ifs: Vec<Expr<U>>,
818-
pub is_async: Int,
818+
pub is_async: bool,
819819
}
820820

821821
#[derive(Clone, Debug, PartialEq)]

ast/src/unparse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'a> Unparser<'a> {
429429

430430
fn unparse_comp<U>(&mut self, generators: &[Comprehension<U>]) -> fmt::Result {
431431
for comp in generators {
432-
self.p(if comp.is_async.to_bool() {
432+
self.p(if comp.is_async {
433433
" async for "
434434
} else {
435435
" for "

parser/src/python.lalrpop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ExpressionStatement: ast::Stmt = {
132132
target: Box::new(set_context(target, ast::ExprContext::Store)),
133133
annotation: Box::new(annotation),
134134
value: rhs.map(Box::new),
135-
simple: ast::Int::new_bool(simple),
135+
simple,
136136
}.into(),
137137
)
138138
},
@@ -1707,7 +1707,7 @@ SingleForComprehension: ast::Comprehension = {
17071707
target: set_context(target, ast::ExprContext::Store),
17081708
iter,
17091709
ifs,
1710-
is_async: ast::Int::new_bool(is_async),
1710+
is_async,
17111711
}
17121712
}
17131713
};

parser/src/python.rs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__ann_assign_name.snap

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__assign_list_comp.snap

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__assign_set_comp.snap

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__parser__tests__generator_expression_argument.snap

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__parser__tests__parse_dict_comprehension.snap

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)