Skip to content

Commit

Permalink
Support NamedExpr
Browse files Browse the repository at this point in the history
Fix #58
  • Loading branch information
serge-sans-paille committed Jul 23, 2021
1 parent 2271bc2 commit 3cc9b4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ ASDL
-- BoolOp() can use left & right?
expr = BoolOp(boolop op, expr* values)
| NamedExpr(expr target, expr value)
| BinOp(expr left, operator op, expr right)
| UnaryOp(unaryop op, expr operand)
| Lambda(arguments args, expr body)
Expand Down
3 changes: 3 additions & 0 deletions gast/gast.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def create_node(self, *args, **kwargs):
('BoolOp', (('op', 'values',),
('lineno', 'col_offset', 'end_lineno', 'end_col_offset',),
(expr,))),
('NamedExpr', (('target', 'value',),
('lineno', 'col_offset', 'end_lineno', 'end_col_offset',),
(expr,))),
('BinOp', (('left', 'op', 'right',),
('lineno', 'col_offset', 'end_lineno', 'end_col_offset',),
(expr,))),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ def test_PosonlyArgs(self):
"], type_ignores=[])")
self.assertEqual(gast.dump(tree), norm)

def test_NamedExpr(self):
code = '(x := 1) '
tree = gast.parse(code)
compile(gast.gast_to_ast(tree), '<test>', 'exec')
norm = ("Module(body=[Expr(value=NamedExpr(target=Name(id='x',"
" ctx=Store(), annotation=None, type_comment=None), "
"value=Constant(value=1, kind=None)))], type_ignores="
"[])")
self.assertEqual(gast.dump(tree), norm)

else:

def test_Bytes(self):
Expand Down

0 comments on commit 3cc9b4d

Please sign in to comment.