mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
complain about "global __class__" in a class body (closes #17983)
This commit is contained in:
parent
c032f16d18
commit
1e93b06007
3 changed files with 13 additions and 0 deletions
|
@ -1236,6 +1236,12 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
|||
asdl_seq *seq = s->v.Global.names;
|
||||
for (i = 0; i < asdl_seq_LEN(seq); i++) {
|
||||
identifier name = (identifier)asdl_seq_GET(seq, i);
|
||||
if (st->st_cur->ste_type == ClassBlock &&
|
||||
!PyUnicode_CompareWithASCIIString(name, "__class__")) {
|
||||
PyErr_SetString(PyExc_SyntaxError, "cannot make __class__ global");
|
||||
PyErr_SyntaxLocationEx(st->st_filename, s->lineno, s->col_offset);
|
||||
return 0;
|
||||
}
|
||||
long cur = symtable_lookup(st, name);
|
||||
if (cur < 0)
|
||||
VISIT_QUIT(st, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue