https://github.com/python/cpython/commit/689c420973c5939345e702428a6172047ecdbc06
commit: 689c420973c5939345e702428a6172047ecdbc06
branch: 3.15
author: Irit Katriel <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-12T15:54:04-07:00
summary:
[3.15] gh-156466: fix cleanup on error in codegen_leave_annotations_scope
(#156520)
files:
M Python/codegen.c
diff --git a/Python/codegen.c b/Python/codegen.c
index cb1eb9df53dc3f..cbe8871928ba33 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -746,10 +746,11 @@ codegen_setup_annotations_scope(compiler *c, location loc,
}
static int
-codegen_leave_annotations_scope(compiler *c, location loc)
+codegen_finish_annotations_scope(compiler *c, location loc)
{
ADDOP_IN_SCOPE(c, loc, RETURN_VALUE);
PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 1);
+ _PyCompile_ExitScope(c);
if (co == NULL) {
return ERROR;
}
@@ -783,7 +784,6 @@ codegen_leave_annotations_scope(compiler *c, location loc)
}
Py_SETREF(co->co_localsplusnames, new_names);
- _PyCompile_ExitScope(c);
int ret = codegen_make_closure(c, loc, co, 0);
Py_DECREF(co);
RETURN_IF_ERROR(ret);
@@ -886,7 +886,7 @@ codegen_process_deferred_annotations(compiler *c, location
loc)
Py_DECREF(deferred_anno);
Py_DECREF(conditional_annotation_indices);
- RETURN_IF_ERROR(codegen_leave_annotations_scope(c, loc));
+ RETURN_IF_ERROR(codegen_finish_annotations_scope(c, loc));
RETURN_IF_ERROR(codegen_nameop(
c, loc,
ste->ste_type == ClassBlock ? &_Py_ID(__annotate_func__) :
&_Py_ID(__annotate__),
@@ -1192,7 +1192,7 @@ codegen_function_annotations(compiler *c, location loc,
c, codegen_annotations_in_scope(c, loc, args, returns,
&annotations_len)
);
ADDOP_I_IN_SCOPE(c, loc, BUILD_MAP, annotations_len);
- RETURN_IF_ERROR(codegen_leave_annotations_scope(c, loc));
+ RETURN_IF_ERROR(codegen_finish_annotations_scope(c, loc));
return MAKE_FUNCTION_ANNOTATE;
}
else {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]