Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r72347:8f89bba8441c
Date: 2014-07-03 23:23 +0200
http://bitbucket.org/pypy/pypy/changeset/8f89bba8441c/

Log:    Apply fix for Cpython Issue14857

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1354,10 +1354,10 @@
         # compile the body proper
         self._handle_body(cls.body)
         # return the (empty) __class__ cell
-        scope = self.scope.lookup("@__class__")
+        scope = self.scope.lookup("__class__")
         if scope == symtable.SCOPE_CELL:
             # Return the cell where to store __class__
-            self.emit_op_arg(ops.LOAD_CLOSURE, self.cell_vars["@__class__"])
+            self.emit_op_arg(ops.LOAD_CLOSURE, self.cell_vars["__class__"])
         else:
             # This happens when nobody references the cell
             self.load_const(self.space.w_None)
diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -240,7 +240,7 @@
     def note_symbol(self, identifier, role):
         # Special-case super: it counts as a use of __class__
         if role == SYM_USED and identifier == 'super':
-            self.note_symbol('@__class__', SYM_USED)
+            self.note_symbol('__class__', SYM_USED)
         return Scope.note_symbol(self, identifier, role)
 
     def note_yield(self, yield_node):
@@ -298,12 +298,12 @@
         return misc.mangle(name, self.name)
 
     def _pass_special_names(self, local, new_bound):
-        assert '@__class__' in local
-        new_bound['@__class__'] = None
+        assert '__class__' in local
+        new_bound['__class__'] = None
 
     def _finalize_cells(self, free):
         for name, role in self.symbols.iteritems():
-            if role == SCOPE_LOCAL and name in free and name == '@__class__':
+            if role == SCOPE_LOCAL and name in free and name == '__class__':
                 self.symbols[name] = SCOPE_CELL
                 del free[name]
 
@@ -392,7 +392,7 @@
             clsdef.kwargs.walkabout(self)
         self.visit_sequence(clsdef.decorator_list)
         self.push_scope(ClassScope(clsdef), clsdef)
-        self.note_symbol('@__class__', SYM_ASSIGNED)
+        self.note_symbol('__class__', SYM_ASSIGNED)
         self.note_symbol('__locals__', SYM_PARAM)
         self.visit_sequence(clsdef.body)
         self.pop_scope()
diff --git a/pypy/module/__builtin__/descriptor.py 
b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -67,7 +67,7 @@
                     "super(): arg[0] deleted"))
         index = 0
         for name in code.co_freevars:
-            if name == "@__class__":
+            if name == "__class__":
                 break
             index += 1
         else:
diff --git a/pypy/module/__builtin__/test/test_descriptor.py 
b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -400,3 +400,21 @@
         assert x.y == 42
         del x.x
         assert x.z == 42
+
+    def test___class___variable(self):
+        class X:
+            def f(self):
+                return __class__
+        assert X().f() is X
+
+        class X:
+            @classmethod
+            def f(cls):
+                return __class__
+        assert X.f() is X
+
+        class X:
+            @staticmethod
+            def f():
+                return __class__
+        assert X.f() is X
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to