Skip to content

Commit 2cab319

Browse files
authored
[3.15] gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473) (GH-156498)
(cherry picked from commit 24e5a55)
1 parent b079bef commit 2cab319

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
@@ -709,16 +709,8 @@ codegen_enter_scope(compiler *c, identifier name, int scope_type,
709709
}
710710

711711
static int
712-
codegen_setup_annotations_scope(compiler *c, location loc,
713-
void *key, PyObject *name)
712+
codegen_emit_annotations_prologue(compiler *c, location loc)
714713
{
715-
_PyCompile_CodeUnitMetadata umd = {
716-
.u_posonlyargcount = 1,
717-
};
718-
RETURN_IF_ERROR(
719-
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
720-
key, loc.lineno, NULL, &umd));
721-
722714
// if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
723715
PyObject *value_with_fake_globals = PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
724716
if (value_with_fake_globals == NULL) {
@@ -738,6 +730,21 @@ codegen_setup_annotations_scope(compiler *c, location loc,
738730
return SUCCESS;
739731
}
740732

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

0 commit comments

Comments
 (0)