https://github.com/python/cpython/commit/e93fe16a085a48e4a65c37d55bb386b094ba2390
commit: e93fe16a085a48e4a65c37d55bb386b094ba2390
branch: 3.14
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2026-08-28T10:42:36+01:00
summary:

[3.14] gh-156466: fix cleanup on error in codegen_setup_annotations_scope 
(#156473) (#156499)

gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473)

(cherry picked from commit 24e5a55ccb0c5db68136d29f4c16c0bc21407db2)

files:
M Python/codegen.c

diff --git a/Python/codegen.c b/Python/codegen.c
index 766d54d069927e..d13f8419a61bcd 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -663,16 +663,8 @@ codegen_enter_scope(compiler *c, identifier name, int 
scope_type,
 }
 
 static int
-codegen_setup_annotations_scope(compiler *c, location loc,
-                                void *key, PyObject *name)
+codegen_emit_annotations_prologue(compiler *c, location loc)
 {
-    _PyCompile_CodeUnitMetadata umd = {
-        .u_posonlyargcount = 1,
-    };
-    RETURN_IF_ERROR(
-        codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
-                            key, loc.lineno, NULL, &umd));
-
     // if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
     PyObject *value_with_fake_globals = 
PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
     assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
@@ -688,6 +680,21 @@ codegen_setup_annotations_scope(compiler *c, location loc,
     return SUCCESS;
 }
 
+static int
+codegen_setup_annotations_scope(compiler *c, location loc,
+                                void *key, PyObject *name)
+{
+    _PyCompile_CodeUnitMetadata umd = {
+        .u_posonlyargcount = 1,
+    };
+    RETURN_IF_ERROR(
+        codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
+                            key, loc.lineno, NULL, &umd));
+
+    RETURN_IF_ERROR_IN_SCOPE(c, codegen_emit_annotations_prologue(c, loc));
+    return SUCCESS;
+}
+
 static int
 codegen_leave_annotations_scope(compiler *c, location loc)
 {

_______________________________________________
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