Commits

Amaury Forgeot d'Arc committed 37095df

Fix for cpython Issue #17983

Comments (0)

Files changed (2)

pypy/interpreter/astcompiler/symtable.py

 
     def visit_Global(self, glob):
         for name in glob.names:
+            if isinstance(self.scope, ClassScope) and name == '__class__':
+                raise SyntaxError("cannot make __class__ global",
+                                  glob.lineno, glob.col_offset)
             old_role = self.scope.lookup_role(name)
             if old_role & (SYM_USED | SYM_ASSIGNED):
                 if old_role & SYM_ASSIGNED:

pypy/interpreter/astcompiler/test/test_compiler.py

         """
         yield self.st, test, "g()", range(3)
 
+    def test__class__global(self):
+        source = """if 1:
+        class X:
+           global __class__
+           def f(self):
+               super()
+        """
+        py.test.raises(SyntaxError, self.simple_test, source, None, None)
+
 
 class AppTestCompiler: