support 'global' in Python class body
authorStefan Behnel <stefan_ml@behnel.de>
Thu, 7 Nov 2013 07:13:35 +0000 (08:13 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Thu, 7 Nov 2013 07:13:35 +0000 (08:13 +0100)
--HG--
rename : tests/run/ass2global.pyx => tests/run/ass2global.py

Cython/Compiler/Symtab.py
tests/run/ass2global.py [moved from tests/run/ass2global.pyx with 57% similarity]

index b38eb97..16e2834 100644 (file)
@@ -1741,6 +1741,14 @@ class PyClassScope(ClassScope):
                 # right thing to do
                 self.entries[name] = entry
 
+    def declare_global(self, name, pos):
+        # Pull entry from global scope into local scope.
+        if self.lookup_here(name):
+            warning(pos, "'%s' redeclared  ", 0)
+        else:
+            entry = self.global_scope().lookup_target(name)
+            self.entries[name] = entry
+
     def add_default_value(self, type):
         return self.outer_scope.add_default_value(type)
 
similarity index 57%
rename from tests/run/ass2global.pyx
rename to tests/run/ass2global.py
index f559b10..c554125 100644 (file)
@@ -4,13 +4,22 @@ __doc__ = u"""
     >>> f(42)
     >>> getg()
     42
+    >>> global_in_class
+    9
 """
 
 g = 5
 
+
 def f(a):
     global g
     g = a
 
+
 def getg():
     return g
+
+
+class Test(object):
+    global global_in_class
+    global_in_class = 9