Mercurial > cpython-lru_cache-weakref
comparison Python/compile.c @ 58707:76cf60e2d005 legacy-trunk
normalize exceptions passed to the __exit__ method #7853
In Python 2.x, exceptions in finally blocks are not normalized. Since with
statements are implemented using finally blocks, ceval.c had to be tweaked to
distinguish between with finally blocks and normal ones.
A test for the finalization of generators containing with statements was also
added.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 05 Feb 2010 02:12:14 +0000 |
| parents | edfed0e32ced |
| children | b879209c202f |
comparison
equal
deleted
inserted
replaced
| 58704:de5fa925dfea | 58707:76cf60e2d005 |
|---|---|
| 2925 VISIT(c, expr, s->v.With.context_expr); | 2925 VISIT(c, expr, s->v.With.context_expr); |
| 2926 ADDOP_JREL(c, SETUP_WITH, finally); | 2926 ADDOP_JREL(c, SETUP_WITH, finally); |
| 2927 | 2927 |
| 2928 /* SETUP_WITH pushes a finally block. */ | 2928 /* SETUP_WITH pushes a finally block. */ |
| 2929 compiler_use_next_block(c, block); | 2929 compiler_use_next_block(c, block); |
| 2930 /* Note that the block is actually called SETUP_WITH in ceval.c, but | |
| 2931 functions the same as SETUP_FINALLY except that exceptions are | |
| 2932 normalized. */ | |
| 2930 if (!compiler_push_fblock(c, FINALLY_TRY, block)) { | 2933 if (!compiler_push_fblock(c, FINALLY_TRY, block)) { |
| 2931 return 0; | 2934 return 0; |
| 2932 } | 2935 } |
| 2933 | 2936 |
| 2934 if (s->v.With.optional_vars) { | 2937 if (s->v.With.optional_vars) { |
