Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11384c6

Browse files
author
Peter Schneider-Kamp
committed
raise error on duplicate function arguments
example: >>> def f(a,a):print a ... SyntaxError: duplicate argument in function definition
1 parent 91826ed commit 11384c6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Python/compile.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,7 @@ com_arglist(c, n)
30923092
node *ch = CHILD(n, i);
30933093
node *fp;
30943094
char *name;
3095+
PyObject *nameval;
30953096
if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR)
30963097
break;
30973098
REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */
@@ -3103,7 +3104,15 @@ com_arglist(c, n)
31033104
sprintf(nbuf, ".%d", i);
31043105
complex = 1;
31053106
}
3106-
com_newlocal(c, name);
3107+
nameval = PyString_InternFromString(name);
3108+
if (nameval == NULL) {
3109+
c->c_errors++;
3110+
}
3111+
if (PyDict_GetItem(c->c_locals, nameval)) {
3112+
com_error(c, PyExc_SyntaxError,"duplicate argument in function definition");
3113+
}
3114+
com_newlocal_o(c, nameval);
3115+
Py_DECREF(nameval);
31073116
c->c_argcount++;
31083117
if (++i >= nch)
31093118
break;

0 commit comments

Comments
 (0)