gh-156466: fix cleanup on error in codegen_setup_annotations_scope (#156473)
diff --git a/Python/codegen.c b/Python/codegen.c
index bedf3b1..df52f2c 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) {
@@ -737,6 +729,21 @@ codegen_setup_annotations_scope(compiler *c, location loc,
}
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)
{
// We want the parameter to __annotate__ to be named "format" in the