Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 18274:86dab0d43b73 legacy-trunk
SF bug #436207: "if 0: yield x" is ignored.
Not anymore <wink>. Pure hack. Doesn't fix any other "if 0:" glitches.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 26 Jun 2001 03:36:28 +0000 |
| parents | 47717e5667eb |
| children | 41243cb4ea05 |
line wrap: on
line diff
--- a/Python/compile.c Mon Jun 25 19:46:25 2001 +0000 +++ b/Python/compile.c Tue Jun 26 03:36:28 2001 +0000 @@ -4840,6 +4840,34 @@ #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 @@ } 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)); }
