diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-06-26 03:36:28 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-06-26 03:36:28 (GMT) |
commit | b6c3ceae79f193e4361651fea61dfb2528bc2746 (patch) | |
tree | f2dbdff39cd430c8dee9c0b2eb15793e25bedaa6 /Python | |
parent | 3e7b1a04a0fe02098ffc03b5c0fc6546a5f7d2d1 (diff) | |
download | cpython-b6c3ceae79f193e4361651fea61dfb2528bc2746.zip cpython-b6c3ceae79f193e4361651fea61dfb2528bc2746.tar.gz cpython-b6c3ceae79f193e4361651fea61dfb2528bc2746.tar.bz2 |
SF bug #436207: "if 0: yield x" is ignored.
Not anymore <wink>. Pure hack. Doesn't fix any other "if 0:" glitches.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index 2ce7487..e82c34c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4840,6 +4840,34 @@ symtable_add_def_o(struct symtable *st, PyObject *dict, #define symtable_add_use(ST, NAME) symtable_add_def((ST), (NAME), USE) +/* Look for a yield stmt under n. Return 1 if found, else 0. */ +static int +look_for_yield(node *n) +{ + int i; + + for (i = 0; i < NCH(n); ++i) { + node *kid = CHILD(n, i); + + switch (TYPE(kid)) { + + case classdef: + case funcdef: + /* Stuff in nested functions and classes can't make + the parent a generator. */ + return 0; + + case yield_stmt: + return 1; + + default: + if (look_for_yield(kid)) + return 1; + } + } + return 0; +} + static void symtable_node(struct symtable *st, node *n) { @@ -4883,8 +4911,12 @@ symtable_node(struct symtable *st, node *n) } case if_stmt: for (i = 0; i + 3 < NCH(n); i += 4) { - if (is_constant_false(NULL, (CHILD(n, i + 1)))) + if (is_constant_false(NULL, (CHILD(n, i + 1)))) { + if (st->st_cur->ste_generator == 0) + st->st_cur->ste_generator = + look_for_yield(CHILD(n, i+3)); continue; + } symtable_node(st, CHILD(n, i + 1)); symtable_node(st, CHILD(n, i + 3)); } |