Commit b211d1e8 authored by Stefan Behnel's avatar Stefan Behnel

support 'global' in Python class body

--HG--
rename : tests/run/ass2global.pyx => tests/run/ass2global.py
parent 3421e034
......@@ -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)
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment