Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def test_annotations(self):
eq('f((x for x in a), 2)')
eq('(((a)))', 'a')
eq('(((a, b)))', '(a, b)')
eq("(x:=10)")
eq("f'{(x:=10):=10}'")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add NamedExpression kind support to ast_unparse.c
13 changes: 13 additions & 0 deletions Python/ast_unparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ append_ast_await(_PyUnicodeWriter *writer, expr_ty e, int level)
return 0;
}

static int
append_named_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
{
APPEND_STR_IF(level > PR_TUPLE, "(");
APPEND_EXPR(e->v.NamedExpr.target, PR_ATOM);
APPEND_STR(":=");
APPEND_EXPR(e->v.NamedExpr.value, PR_ATOM);
APPEND_STR_IF(level > PR_TUPLE, ")");
return 0;
}

static int
append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
{
Expand Down Expand Up @@ -867,6 +878,8 @@ append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
return append_ast_list(writer, e);
case Tuple_kind:
return append_ast_tuple(writer, e, level);
case NamedExpr_kind:
return append_named_expr(writer, e, level);
default:
PyErr_SetString(PyExc_SystemError,
"unknown expression kind");
Expand Down