diff -r df59faf7fa59 Python/symtable.c --- a/Python/symtable.c Sun Dec 11 14:43:18 2016 +0200 +++ b/Python/symtable.c Sun Dec 11 15:04:58 2016 +0100 @@ -5,6 +5,12 @@ #include "structmember.h" /* error strings used for warnings */ +#define GLOBAL_PARAM \ +"name '%U' is parameter and global" + +#define NONLOCAL_PARAM \ +"name '%U' is parameter and nonlocal" + #define GLOBAL_AFTER_ASSIGN \ "name '%U' is assigned to before global declaration" @@ -463,8 +469,7 @@ if (flags & DEF_GLOBAL) { if (flags & DEF_PARAM) { PyErr_Format(PyExc_SyntaxError, - "name '%U' is parameter and global", - name); + GLOBAL_PARAM, name); return error_at_directive(ste, name); } if (flags & DEF_NONLOCAL) { @@ -483,8 +488,7 @@ if (flags & DEF_NONLOCAL) { if (flags & DEF_PARAM) { PyErr_Format(PyExc_SyntaxError, - "name '%U' is parameter and nonlocal", - name); + NONLOCAL_PARAM, name); return error_at_directive(ste, name); } if (!bound) { @@ -1280,6 +1284,14 @@ long cur = symtable_lookup(st, name); if (cur < 0) VISIT_QUIT(st, 0); + if (cur & DEF_PARAM) { + PyErr_Format(PyExc_SyntaxError, + GLOBAL_PARAM, name); + PyErr_SyntaxLocationObject(st->st_filename, + s->lineno, + s->col_offset); + VISIT_QUIT(st, 0); + } if (cur & (DEF_LOCAL | USE | DEF_ANNOT)) { char* msg; if (cur & USE) { @@ -1311,6 +1323,14 @@ long cur = symtable_lookup(st, name); if (cur < 0) VISIT_QUIT(st, 0); + if (cur & DEF_PARAM) { + PyErr_Format(PyExc_SyntaxError, + NONLOCAL_PARAM, name); + PyErr_SyntaxLocationObject(st->st_filename, + s->lineno, + s->col_offset); + VISIT_QUIT(st, 0); + } if (cur & (DEF_LOCAL | USE | DEF_ANNOT)) { char* msg; if (cur & USE) {