summaryrefslogtreecommitdiffstats
path: root/Python/ast_unparse.c
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-05-18 22:10:20 (GMT)
committerPablo Galindo <Pablogsal@gmail.com>2019-05-18 22:10:20 (GMT)
commitfa19a25c238d0769e6a5aa63ce05133d66043556 (patch)
tree077b992633fa929e61a03b606803d84a9f9f524a /Python/ast_unparse.c
parenteab99650799699f766c2660f4cfa8ff3f9e8457f (diff)
downloadcpython-fa19a25c238d0769e6a5aa63ce05133d66043556.zip
cpython-fa19a25c238d0769e6a5aa63ce05133d66043556.tar.gz
cpython-fa19a25c238d0769e6a5aa63ce05133d66043556.tar.bz2
Add support for PEP572 in ast_unparse.c (GH-13337)
Diffstat (limited to 'Python/ast_unparse.c')
-rw-r--r--Python/ast_unparse.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c
index 25a5c69..5f366a1 100644
--- a/Python/ast_unparse.c
+++ b/Python/ast_unparse.c
@@ -810,6 +810,17 @@ append_ast_await(_PyUnicodeWriter *writer, expr_ty e, int level)
}
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)
{
switch (e->kind) {
@@ -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");