https://github.com/python/cpython/commit/8e0159bd2338c8dff93dd443181e3402c88c70a8
commit: 8e0159bd2338c8dff93dd443181e3402c88c70a8
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2026-08-28T15:03:56+01:00
summary:

gh-156466: fix cleanup on error in codegen_leave_annotations_scope (#156497)

files:
M Python/codegen.c

diff --git a/Python/codegen.c b/Python/codegen.c
index ce577314d49fb0..17901cbc1bf976 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -775,10 +775,11 @@ codegen_rename_annotations_format_param(PyCodeObject *co)
 }
 
 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;
     }
@@ -788,7 +789,6 @@ codegen_leave_annotations_scope(compiler *c, location loc)
         return ERROR;
     }
 
-    _PyCompile_ExitScope(c);
     int ret = codegen_make_closure(c, loc, co, 0);
     Py_DECREF(co);
     RETURN_IF_ERROR(ret);
@@ -891,7 +891,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__),
@@ -1197,7 +1197,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]

Reply via email to