Commit 1644e44c authored by Stefan Behnel's avatar Stefan Behnel

Prevent assigned global variables from being marked and treated as closure...

Prevent assigned global variables from being marked and treated as closure variables in generators and coroutines.
Closes #2613.
parent a2776020
...@@ -2677,7 +2677,7 @@ class CreateClosureClasses(CythonTransform): ...@@ -2677,7 +2677,7 @@ class CreateClosureClasses(CythonTransform):
if node.is_generator: if node.is_generator:
for scope in node.local_scope.iter_local_scopes(): for scope in node.local_scope.iter_local_scopes():
for entry in scope.entries.values(): for entry in scope.entries.values():
if not entry.from_closure: if not (entry.from_closure or entry.is_pyglobal or entry.is_cglobal):
entry.in_closure = True entry.in_closure = True
from_closure, in_closure = self.find_entries_used_in_closures(node) from_closure, in_closure = self.find_entries_used_in_closures(node)
......
# mode: run
# tag: pep492, asyncfor, await, gh2613
# Using C-globals in coroutines.
cdef object py_retval
async def test():
"""
>>> t = test()
>>> try: t.send(None)
... except StopIteration as ex:
... print(ex.args[0] if ex.args else None)
... else: print("NOT STOPPED!")
None
"""
global py_retval
py_retval = {'foo': 42}
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