From fa19a25c238d0769e6a5aa63ce05133d66043556 Mon Sep 17 00:00:00 2001 From: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> Date: Sun, 19 May 2019 01:10:20 +0300 Subject: Add support for PEP572 in ast_unparse.c (GH-13337) --- Python/ast_unparse.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Python/ast_unparse.c') diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 25a5c698a1d..5f366a188b3 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -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) { @@ -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"); -- cgit v1.2.3