diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-05-15 21:17:25 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-05-15 21:17:25 (GMT) |
commit | 1e93b060077db01ceca0cdbad00ff358fee6f104 (patch) | |
tree | a9812ecd17301e563a020e9d122e6a52d3b7fa3a /Python/symtable.c | |
parent | c032f16d181203e5df458b09c4583a6389f78331 (diff) | |
download | cpython-1e93b060077db01ceca0cdbad00ff358fee6f104.zip cpython-1e93b060077db01ceca0cdbad00ff358fee6f104.tar.gz cpython-1e93b060077db01ceca0cdbad00ff358fee6f104.tar.bz2 |
complain about "global __class__" in a class body (closes #17983)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index 55898f9..e686d9e 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -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); |