mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Derived from Thomas Wouters's patch on the Iterators list, but doesn't try to read c->c_block[c->c_nblocks].
This commit is contained in:
parent
1bf198e946
commit
95c80f8439
1 changed files with 10 additions and 0 deletions
|
@ -2659,10 +2659,20 @@ com_return_stmt(struct compiling *c, node *n)
|
|||
static void
|
||||
com_yield_stmt(struct compiling *c, node *n)
|
||||
{
|
||||
int i;
|
||||
REQ(n, yield_stmt); /* 'yield' testlist */
|
||||
if (!c->c_infunction) {
|
||||
com_error(c, PyExc_SyntaxError, "'yield' outside function");
|
||||
}
|
||||
|
||||
for (i = 0; i < c->c_nblocks; ++i) {
|
||||
if (c->c_block[i] == SETUP_FINALLY) {
|
||||
com_error(c, PyExc_SyntaxError,
|
||||
"'yield' not allowed in a 'try' block "
|
||||
"with a 'finally' clause");
|
||||
return;
|
||||
}
|
||||
}
|
||||
com_node(c, CHILD(n, 1));
|
||||
com_addbyte(c, YIELD_VALUE);
|
||||
com_pop(c, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue