diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-05-18 22:40:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-18 22:40:22 (GMT) |
commit | da6129e821099c1372d511a11d18af83d6d5d128 (patch) | |
tree | aaeab4fe509a089fb2937aca046e1de338f31971 /Python | |
parent | fa19a25c238d0769e6a5aa63ce05133d66043556 (diff) | |
download | cpython-da6129e821099c1372d511a11d18af83d6d5d128.zip cpython-da6129e821099c1372d511a11d18af83d6d5d128.tar.gz cpython-da6129e821099c1372d511a11d18af83d6d5d128.tar.bz2 |
bpo-36961: Handle positional-only arguments in uparse.c (GH-13412)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast_unparse.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 5f366a1..f1b991a 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -193,22 +193,30 @@ static int append_ast_args(_PyUnicodeWriter *writer, arguments_ty args) { bool first; - Py_ssize_t i, di, arg_count, default_count; + Py_ssize_t i, di, arg_count, posonlyarg_count, default_count; first = true; - /* positional arguments with defaults */ + /* positional-only and positional arguments with defaults */ + posonlyarg_count = asdl_seq_LEN(args->posonlyargs); arg_count = asdl_seq_LEN(args->args); default_count = asdl_seq_LEN(args->defaults); - for (i = 0; i < arg_count; i++) { + for (i = 0; i < posonlyarg_count + arg_count; i++) { APPEND_STR_IF_NOT_FIRST(", "); - APPEND(arg, (arg_ty)asdl_seq_GET(args->args, i)); + if (i < posonlyarg_count){ + APPEND(arg, (arg_ty)asdl_seq_GET(args->posonlyargs, i)); + } else { + APPEND(arg, (arg_ty)asdl_seq_GET(args->args, i-posonlyarg_count)); + } - di = i - arg_count + default_count; + di = i - posonlyarg_count - arg_count + default_count; if (di >= 0) { APPEND_STR("="); APPEND_EXPR((expr_ty)asdl_seq_GET(args->defaults, di), PR_TEST); } + if (posonlyarg_count && i + 1 == posonlyarg_count) { + APPEND_STR(", /"); + } } /* vararg, or bare '*' if no varargs but keyword-only arguments present */ @@ -251,7 +259,9 @@ static int append_ast_lambda(_PyUnicodeWriter *writer, expr_ty e, int level) { APPEND_STR_IF(level > PR_TEST, "("); - APPEND_STR(asdl_seq_LEN(e->v.Lambda.args->args) ? "lambda " : "lambda"); + Py_ssize_t n_positional = (asdl_seq_LEN(e->v.Lambda.args->args) + + asdl_seq_LEN(e->v.Lambda.args->posonlyargs)); + APPEND_STR(n_positional ? "lambda " : "lambda"); APPEND(args, e->v.Lambda.args); APPEND_STR(": "); APPEND_EXPR(e->v.Lambda.body, PR_TEST); |