diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-04-03 20:37:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 20:37:13 +0100 |
commit | 254ec783411d9d16e51f1116f98918be2ef0e884 (patch) | |
tree | e0520ead772c7d702bec0a4423ab538a4026e893 /Python/compile.c | |
parent | bpo-40131: Fix source and target order in zipapp example (GH-19290) (diff) | |
download | cpython-254ec783411d9d16e51f1116f98918be2ef0e884.tar.gz cpython-254ec783411d9d16e51f1116f98918be2ef0e884.tar.bz2 cpython-254ec783411d9d16e51f1116f98918be2ef0e884.zip |
bpo-40147: Move the check for duplicate keywords to the compiler (GH-19289)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index 01700e0e78c..b1c1982fd2c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4050,6 +4050,31 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e) } static int +validate_keywords(struct compiler *c, asdl_seq* keywords) { + int nkeywords = asdl_seq_LEN(keywords); + for (int i = 0; i < nkeywords; i++) { + keyword_ty key = ((keyword_ty)asdl_seq_GET(keywords, i)); + if (key->arg == NULL) { + continue; + } + for (int j = i+1; j < nkeywords; j++) { + keyword_ty other = ((keyword_ty)asdl_seq_GET(keywords, j)); + if (other->arg && !PyUnicode_Compare(key->arg, other->arg)) { + PyObject *msg = PyUnicode_FromFormat("keyword argument repeated: %U", key->arg); + if (msg == NULL) { + return -1; + } + c->u->u_col_offset = other->col_offset; + compiler_error(c, PyUnicode_AsUTF8(msg)); + Py_DECREF(msg); + return -1; + } + } + } + return 0; +} + +static int compiler_call(struct compiler *c, expr_ty e) { int ret = maybe_optimize_method_call(c, e); @@ -4165,6 +4190,10 @@ compiler_call_helper(struct compiler *c, { Py_ssize_t i, nseen, nelts, nkwelts; + if (validate_keywords(c, keywords) == -1) { + return 0; + } + nelts = asdl_seq_LEN(args); nkwelts = asdl_seq_LEN(keywords); |