Allow try/except in with block

This commit is contained in:
Dino Viehland 2025-10-23 10:06:18 -07:00
parent 34ea0a5b1d
commit 5166d39584
8 changed files with 46 additions and 25 deletions

View file

@ -787,6 +787,26 @@ _PyCompile_TopFBlock(compiler *c)
return &c->u->u_fblock[c->u->u_nfblocks - 1];
}
bool
_PyCompile_InExceptionHandler(compiler *c)
{
for (Py_ssize_t i = c->u->u_nfblocks; i < c->u->u_nfblocks; i++) {
fblockinfo *block = &c->u->u_fblock[i];
switch (block->fb_type) {
case COMPILE_FBLOCK_TRY_EXCEPT:
case COMPILE_FBLOCK_FINALLY_TRY:
case COMPILE_FBLOCK_FINALLY_END:
case COMPILE_FBLOCK_EXCEPTION_HANDLER:
case COMPILE_FBLOCK_EXCEPTION_GROUP_HANDLER:
case COMPILE_FBLOCK_HANDLER_CLEANUP:
return true;
default:
break;
}
}
return false;
}
void
_PyCompile_DeferredAnnotations(compiler *c,
PyObject **deferred_annotations,