From: Stefan Behnel Date: Thu, 7 Nov 2013 07:13:35 +0000 (+0100) Subject: support 'global' in Python class body X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b211d1e8ddf8cbba69bcaae8c81687ef1168bb84;p=platform%2Fupstream%2Fpython-cython.git support 'global' in Python class body --HG-- rename : tests/run/ass2global.pyx => tests/run/ass2global.py --- diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index b38eb97..16e2834 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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) diff --git a/tests/run/ass2global.pyx b/tests/run/ass2global.py similarity index 57% rename from tests/run/ass2global.pyx rename to tests/run/ass2global.py index f559b10..c554125 100644 --- a/tests/run/ass2global.pyx +++ b/tests/run/ass2global.py @@ -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