Skip to content

Commit 8e0159b

Browse files
authored
gh-156466: fix cleanup on error in codegen_leave_annotations_scope (#156497)
1 parent 0e29768 commit 8e0159b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Python/codegen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,11 @@ codegen_rename_annotations_format_param(PyCodeObject *co)
775775
}
776776

777777
static int
778-
codegen_leave_annotations_scope(compiler *c, location loc)
778+
codegen_finish_annotations_scope(compiler *c, location loc)
779779
{
780780
ADDOP_IN_SCOPE(c, loc, RETURN_VALUE);
781781
PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 1);
782+
_PyCompile_ExitScope(c);
782783
if (co == NULL) {
783784
return ERROR;
784785
}
@@ -788,7 +789,6 @@ codegen_leave_annotations_scope(compiler *c, location loc)
788789
return ERROR;
789790
}
790791

791-
_PyCompile_ExitScope(c);
792792
int ret = codegen_make_closure(c, loc, co, 0);
793793
Py_DECREF(co);
794794
RETURN_IF_ERROR(ret);
@@ -891,7 +891,7 @@ codegen_process_deferred_annotations(compiler *c, location loc)
891891
Py_DECREF(deferred_anno);
892892
Py_DECREF(conditional_annotation_indices);
893893

894-
RETURN_IF_ERROR(codegen_leave_annotations_scope(c, loc));
894+
RETURN_IF_ERROR(codegen_finish_annotations_scope(c, loc));
895895
RETURN_IF_ERROR(codegen_nameop(
896896
c, loc,
897897
ste->ste_type == ClassBlock ? &_Py_ID(__annotate_func__) : &_Py_ID(__annotate__),
@@ -1197,7 +1197,7 @@ codegen_function_annotations(compiler *c, location loc,
11971197
c, codegen_annotations_in_scope(c, loc, args, returns, &annotations_len)
11981198
);
11991199
ADDOP_I_IN_SCOPE(c, loc, BUILD_MAP, annotations_len);
1200-
RETURN_IF_ERROR(codegen_leave_annotations_scope(c, loc));
1200+
RETURN_IF_ERROR(codegen_finish_annotations_scope(c, loc));
12011201
return MAKE_FUNCTION_ANNOTATE;
12021202
}
12031203
else {

0 commit comments

Comments
 (0)