Skip to content

Commit b0df453

Browse files
committed
Add ? before *
Signed-off-by: harupy <hkawamura0130@gmail.com>
1 parent f4363c8 commit b0df453

4 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎compiler/ast/Python.asdl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Python
6060
| UnaryOp(unaryop op, expr operand)
6161
| Lambda(arguments args, expr body)
6262
| IfExp(expr test, expr body, expr orelse)
63-
| Dict(expr* keys, expr* values)
63+
| Dict(expr?* keys, expr* values)
6464
| Set(expr* elts)
6565
| ListComp(expr elt, comprehension* generators)
6666
| SetComp(expr elt, comprehension* generators)

‎compiler/ast/asdl.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ def _parse_optional_attributes(self):
340340

341341
def _parse_optional_field_quantifier(self):
342342
is_seq, is_opt = False, False
343+
if self.cur_token.kind == TokenKind.Question:
344+
is_opt = True
345+
self._advance()
343346
if self.cur_token.kind == TokenKind.Asterisk:
344347
is_seq = True
345348
self._advance()
346-
elif self.cur_token.kind == TokenKind.Question:
347-
is_opt = True
348-
self._advance()
349349
return is_seq, is_opt
350350

351351
def _advance(self):

‎compiler/ast/asdl_rs.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,7 @@ def visitField(self, field, parent, vis, depth, constructor=None):
240240
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
241241
if fieldtype and fieldtype.boxed and (not (parent.product or field.seq) or field.opt):
242242
typ = f"Box<{typ}>"
243-
if field.opt or (
244-
# Add `Option` to allow `Dict.keys` to contain `None` for dictionary unpacking
245-
# in a dict literal.
246-
constructor == "Dict" and field.name == "keys"
247-
):
243+
if field.opt:
248244
typ = f"Option<{typ}>"
249245
if field.seq:
250246
typ = f"Vec<{typ}>"

‎compiler/ast/src/ast_gen.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub enum ExprKind<U = ()> {
195195
orelse: Box<Expr<U>>,
196196
},
197197
Dict {
198-
keys: Vec<Option<Expr<U>>>,
198+
keys: Vec<Option<Box<Expr<U>>>>,
199199
values: Vec<Expr<U>>,
200200
},
201201
Set {

0 commit comments

Comments
 (0)