diff options
| author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-17 05:49:47 +0300 |
|---|---|---|
| committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-17 20:27:00 +0300 |
| commit | b7e90ea07890392b7e31ae5079a539b474b16d81 (patch) | |
| tree | 9be43cfa538ff0387de837c2b44ec1481bc23997 /tests | |
| parent | f26a30710c77299a715318bc487e1874d1bf9984 (diff) | |
objgenerator: Generator must execute in its defining lexical context.
I.e. with its own globals. So, just as for functions, we need to switch
globals when resuming a generator.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/gen_context.py | 9 | ||||
| -rw-r--r-- | tests/basics/gen_context2.py | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/tests/basics/gen_context.py b/tests/basics/gen_context.py new file mode 100644 index 000000000..02f153146 --- /dev/null +++ b/tests/basics/gen_context.py @@ -0,0 +1,9 @@ +import gen_context2 + +GLOBAL = "GLOBAL" + +def gen(): + print(GLOBAL) + yield 1 + +gen_context2.call(gen()) diff --git a/tests/basics/gen_context2.py b/tests/basics/gen_context2.py new file mode 100644 index 000000000..0d8048afc --- /dev/null +++ b/tests/basics/gen_context2.py @@ -0,0 +1,2 @@ +def call(g): + next(g) |
