https://github.com/python/cpython/commit/9aa1f60e2dedd8a67c42fb4f4c56858b6ba5b947
commit: 9aa1f60e2dedd8a67c42fb4f4c56858b6ba5b947
branch: main
author: Irit Katriel <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2024-09-16T06:58:18-07:00
summary:
gh-124058: remove _PyCompile_IsNestedScope, roll it into
_PyCompile_IsInteractive (#124061)
files:
M Include/internal/pycore_compile.h
M Python/codegen.c
M Python/compile.c
diff --git a/Include/internal/pycore_compile.h
b/Include/internal/pycore_compile.h
index 2304d698474355..f089eb05097b52 100644
--- a/Include/internal/pycore_compile.h
+++ b/Include/internal/pycore_compile.h
@@ -133,8 +133,7 @@ int _PyCompile_LookupCellvar(struct _PyCompiler *c,
PyObject *name);
int _PyCompile_ResolveNameop(struct _PyCompiler *c, PyObject *mangled, int
scope,
_PyCompile_optype *optype, Py_ssize_t *arg);
-int _PyCompile_IsInteractive(struct _PyCompiler *c);
-int _PyCompile_IsNestedScope(struct _PyCompiler *c);
+int _PyCompile_IsInteractiveTopLevel(struct _PyCompiler *c);
int _PyCompile_IsInInlinedComp(struct _PyCompiler *c);
int _PyCompile_ScopeType(struct _PyCompiler *c);
int _PyCompile_OptimizationLevel(struct _PyCompiler *c);
diff --git a/Python/codegen.c b/Python/codegen.c
index 5565d3011c465a..0305f4299aec56 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -70,8 +70,7 @@ typedef struct _PyCompiler compiler;
#define SYMTABLE(C) _PyCompile_Symtable(C)
#define SYMTABLE_ENTRY(C) _PyCompile_SymtableEntry(C)
#define OPTIMIZATION_LEVEL(C) _PyCompile_OptimizationLevel(C)
-#define IS_INTERACTIVE(C) _PyCompile_IsInteractive(C)
-#define IS_NESTED_SCOPE(C) _PyCompile_IsNestedScope(C)
+#define IS_INTERACTIVE_TOP_LEVEL(C) _PyCompile_IsInteractiveTopLevel(C)
#define SCOPE_TYPE(C) _PyCompile_ScopeType(C)
#define QUALNAME(C) _PyCompile_Qualname(C)
#define METADATA(C) _PyCompile_Metadata(C)
@@ -2823,7 +2822,7 @@ codegen_assert(compiler *c, stmt_ty s)
static int
codegen_stmt_expr(compiler *c, location loc, expr_ty value)
{
- if (IS_INTERACTIVE(c) && !IS_NESTED_SCOPE(c)) {
+ if (IS_INTERACTIVE_TOP_LEVEL(c)) {
VISIT(c, expr, value);
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
ADDOP(c, NO_LOCATION, POP_TOP);
diff --git a/Python/compile.c b/Python/compile.c
index e1d2c30944d132..cdd4878257525f 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1204,17 +1204,12 @@ _PyCompile_OptimizationLevel(compiler *c)
}
int
-_PyCompile_IsInteractive(compiler *c)
-{
- return c->c_interactive;
-}
-
-int
-_PyCompile_IsNestedScope(compiler *c)
+_PyCompile_IsInteractiveTopLevel(compiler *c)
{
assert(c->c_stack != NULL);
assert(PyList_CheckExact(c->c_stack));
- return PyList_GET_SIZE(c->c_stack) > 0;
+ bool is_nested_scope = PyList_GET_SIZE(c->c_stack) > 0;
+ return c->c_interactive && !is_nested_scope;
}
int
_______________________________________________
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]