mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
Add support for PEP572 in ast_unparse.c (GH-13337)
This commit is contained in:
parent
eab9965079
commit
fa19a25c23
3 changed files with 16 additions and 0 deletions
|
@ -275,6 +275,8 @@ class AnnotationsFutureTestCase(unittest.TestCase):
|
||||||
eq('f((x for x in a), 2)')
|
eq('f((x for x in a), 2)')
|
||||||
eq('(((a)))', 'a')
|
eq('(((a)))', 'a')
|
||||||
eq('(((a, b)))', '(a, b)')
|
eq('(((a, b)))', '(a, b)')
|
||||||
|
eq("(x:=10)")
|
||||||
|
eq("f'{(x:=10):=10}'")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add NamedExpression kind support to ast_unparse.c
|
|
@ -809,6 +809,17 @@ append_ast_await(_PyUnicodeWriter *writer, expr_ty e, int level)
|
||||||
return 0;
|
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
|
static int
|
||||||
append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
|
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);
|
return append_ast_list(writer, e);
|
||||||
case Tuple_kind:
|
case Tuple_kind:
|
||||||
return append_ast_tuple(writer, e, level);
|
return append_ast_tuple(writer, e, level);
|
||||||
|
case NamedExpr_kind:
|
||||||
|
return append_named_expr(writer, e, level);
|
||||||
default:
|
default:
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"unknown expression kind");
|
"unknown expression kind");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue