https://github.com/python/cpython/commit/bfbd499ff1fb962c6b11f1b5f8841c12850a94ac
commit: bfbd499ff1fb962c6b11f1b5f8841c12850a94ac
branch: 3.13
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2026-09-17T19:15:10+01:00
summary:

[3.13] gh-156466: fix cleanup on error after Enter in codegen_enter_scope 
(#156615)

files:
M Python/compile.c

diff --git a/Python/compile.c b/Python/compile.c
index a0b7df0870e8267..2c7cb9185d3e321 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1082,6 +1082,8 @@ codegen_addop_j(instr_sequence *seq, location loc,
     return _PyInstructionSequence_Addop(seq, opcode, target.id, loc);
 }
 
+static void compiler_exit_scope(struct compiler *c);
+
 #define RETURN_IF_ERROR_IN_SCOPE(C, CALL) { \
     if ((CALL) < 0) { \
         compiler_exit_scope((C)); \
@@ -1178,6 +1180,23 @@ codegen_addop_j(instr_sequence *seq, location loc,
 }
 
 
+static int
+codegen_init_new_scope(struct compiler *c, location loc)
+{
+    if (c->u->u_scope_type == COMPILER_SCOPE_MODULE) {
+        loc.lineno = 0;
+    }
+    else {
+        RETURN_IF_ERROR(compiler_set_qualname(c));
+    }
+    ADDOP_I(c, loc, RESUME, RESUME_AT_FUNC_START);
+
+    if (c->u->u_scope_type == COMPILER_SCOPE_MODULE) {
+        loc.lineno = -1;
+    }
+    return SUCCESS;
+}
+
 static int
 compiler_enter_scope(struct compiler *c, identifier name,
                      int scope_type, void *key, int lineno)
@@ -1288,17 +1307,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
 
     c->c_nestlevel++;
 
-    if (u->u_scope_type == COMPILER_SCOPE_MODULE) {
-        loc.lineno = 0;
-    }
-    else {
-        RETURN_IF_ERROR(compiler_set_qualname(c));
-    }
-    ADDOP_I(c, loc, RESUME, RESUME_AT_FUNC_START);
-
-    if (u->u_scope_type == COMPILER_SCOPE_MODULE) {
-        loc.lineno = -1;
-    }
+    RETURN_IF_ERROR_IN_SCOPE(c, codegen_init_new_scope(c, loc));
     return SUCCESS;
 }
 

_______________________________________________
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