summaryrefslogtreecommitdiff
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-05-15 16:17:25 -0500
committerBenjamin Peterson <benjamin@python.org>2013-05-15 16:17:25 -0500
commite5dfecf88c42a98f791f62eba8fb305266765295 (patch)
tree7ce62f047eae0df4764dfc0cda3e87255059466d /Python/symtable.c
parent5ed7e986b6462860cedf4bbb07a791c641208784 (diff)
downloadcpython-e5dfecf88c42a98f791f62eba8fb305266765295.tar.gz
complain about "global __class__" in a class body (closes #17983)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 55898f99bf..e686d9ebc3 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);