From 80623c3fd09758889ac41d5854b81154f05c90c8 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 29 Aug 2026 05:14:29 -0700 Subject: [PATCH] gh-156466: Fix additional compiler scope cleanup errors (GH-156547) (cherry picked from commit f4874f381c1ef9a3e0e17fde870f2d38d89e043b) Co-authored-by: Jelle Zijlstra --- Python/codegen.c | 2 +- Python/compile.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Python/codegen.c b/Python/codegen.c index 9649bad4b3dd09a..18c1fd9fa127ce8 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -1563,7 +1563,7 @@ codegen_class_body(compiler *c, stmt_ty s, int firstlineno) ADDOP_N_IN_SCOPE(c, loc, STORE_DEREF, &_Py_ID(__classdict__), cellvars); } if (SYMTABLE_ENTRY(c)->ste_has_conditional_annotations) { - ADDOP_I(c, loc, BUILD_SET, 0); + ADDOP_I_IN_SCOPE(c, loc, BUILD_SET, 0); ADDOP_N_IN_SCOPE(c, loc, STORE_DEREF, &_Py_ID(__conditional_annotations__), cellvars); } /* compile the body proper */ diff --git a/Python/compile.c b/Python/compile.c index 6c5ef5329ffc3aa..aa0d1b0ed313743 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1687,7 +1687,9 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags, finally: Py_XDECREF(consts_list); Py_XDECREF(metadata); - _PyCompile_ExitScope(c); + if (c->u != NULL) { + _PyCompile_ExitScope(c); + } compiler_free(c); _PyArena_Free(arena); return res;