https://github.com/python/cpython/commit/24e5a55ccb0c5db68136d29f4c16c0bc21407db2
commit: 24e5a55ccb0c5db68136d29f4c16c0bc21407db2
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2026-08-27T21:11:05+01:00
summary:
gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473)
files:
M Python/codegen.c
diff --git a/Python/codegen.c b/Python/codegen.c
index bedf3b17c52ce4..df52f2c734e69a 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -707,16 +707,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) {
@@ -736,6 +728,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_rename_annotations_format_param(PyCodeObject *co)
{
_______________________________________________
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]