diff Python/symtable.c @ 83784:cd9141a4f999 3.3

complain about "global __class__" in a class body (closes #17983)
author Benjamin Peterson <benjamin@python.org>
date Wed, 15 May 2013 16:17:25 -0500
parents ffb2fa900cb7
children 86783c4fd528 e74f4d6c0c81
line wrap: on
line diff
--- a/Python/symtable.c	Wed May 15 19:42:39 2013 +0200
+++ b/Python/symtable.c	Wed May 15 16:17:25 2013 -0500
@@ -1236,6 +1236,12 @@
         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);