Skip to content

Commit 24e5a55

Browse files
authored
gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473)
1 parent 45e5b1b commit 24e5a55

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Python/codegen.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,16 +707,8 @@ codegen_enter_scope(compiler *c, identifier name, int scope_type,
707707
}
708708

709709
static int
710-
codegen_setup_annotations_scope(compiler *c, location loc,
711-
void *key, PyObject *name)
710+
codegen_emit_annotations_prologue(compiler *c, location loc)
712711
{
713-
_PyCompile_CodeUnitMetadata umd = {
714-
.u_posonlyargcount = 1,
715-
};
716-
RETURN_IF_ERROR(
717-
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
718-
key, loc.lineno, NULL, &umd));
719-
720712
// if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
721713
PyObject *value_with_fake_globals = PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
722714
if (value_with_fake_globals == NULL) {
@@ -736,6 +728,21 @@ codegen_setup_annotations_scope(compiler *c, location loc,
736728
return SUCCESS;
737729
}
738730

731+
static int
732+
codegen_setup_annotations_scope(compiler *c, location loc,
733+
void *key, PyObject *name)
734+
{
735+
_PyCompile_CodeUnitMetadata umd = {
736+
.u_posonlyargcount = 1,
737+
};
738+
RETURN_IF_ERROR(
739+
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
740+
key, loc.lineno, NULL, &umd));
741+
742+
RETURN_IF_ERROR_IN_SCOPE(c, codegen_emit_annotations_prologue(c, loc));
743+
return SUCCESS;
744+
}
745+
739746
static int
740747
codegen_rename_annotations_format_param(PyCodeObject *co)
741748
{

0 commit comments

Comments
 (0)