https://github.com/python/cpython/commit/2cab3197a53b84ef0597020880d2dae2b0e677d4
commit: 2cab3197a53b84ef0597020880d2dae2b0e677d4
branch: 3.15
author: Irit Katriel <[email protected]>
committer: encukou <[email protected]>
date: 2026-10-12T14:21:42+02:00
summary:
[3.15] gh-156466: fix cleanup on error in codegen_setup_annotations_scope
(#156473) (GH-156498)
(cherry picked from commit 24e5a55ccb0c5db68136d29f4c16c0bc21407db2)
files:
M Python/codegen.c
diff --git a/Python/codegen.c b/Python/codegen.c
index 491dc1262903ec..cb1eb9df53dc3f 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -709,16 +709,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);
if (value_with_fake_globals == NULL) {
@@ -738,6 +730,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]