8000 gh-124058: remove _PyCompile_IsNestedScope, roll it into _PyCompile_I… · python/cpython@9aa1f60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9aa1f60

Browse files
authored
gh-124058: remove _PyCompile_IsNestedScope, roll it into _PyCompile_IsInteractive (#124061)
1 parent 453da53 commit 9aa1f60

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

Include/internal/pycore_compile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ int _PyCompile_LookupCellvar(struct _PyCompiler *c, PyObject *name);
133133
int _PyCompile_ResolveNameop(struct _PyCompiler *c, PyObject *mangled, int scope,
134134
_PyCompile_optype *optype, Py_ssize_t *arg);
135135

136-
int _PyCompile_IsInteractive(struct _PyCompiler *c);
137-
int _PyCompile_IsNestedScope(struct _PyCompiler *c);
136+
int _PyCompile_IsInteractiveTopLevel(struct _PyCompiler *c);
138137
int _PyCompile_IsInInlinedComp(struct _PyCompiler *c);
139138
int _PyCompile_ScopeType(struct _PyCompiler *c);
140139
int _PyCompile_OptimizationLevel(struct _PyCompiler *c);

Python/codegen.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ typedef struct _PyCompiler compiler;
7070
#define SYMTABLE(C) _PyCompile_Symtable(C)
7171
#define SYMTABLE_ENTRY(C) _PyCompile_SymtableEntry(C)
7272
#define OPTIMIZATION_LEVEL(C) _PyCompile_OptimizationLevel(C)
73-
#define IS_INTERACTIVE(C) _PyCompile_IsInteractive(C)
74-
#define IS_NESTED_SCOPE(C) _PyCompile_IsNestedScope(C)
73+
#define IS_INTERACTIVE_TOP_LEVEL(C) _PyCompile_IsInteractiveTopLevel(C)
7574
#define SCOPE_TYPE(C) _PyCompile_ScopeType(C)
7675
#define QUALNAME(C) _PyCompile_Qualname(C)
7776
#define METADATA(C) _PyCompile_Metadata(C)
@@ -2823,7 +2822,7 @@ codegen_assert(compiler *c, stmt_ty s)
28232822
static int
28242823
codegen_stmt_expr(compiler *c, location loc, expr_ty value)
28252824
{
2826-
if (IS_INTERACTIVE(c) && !IS_NESTED_SCOPE(c)) {
2825+
if (IS_INTERACTIVE_TOP_LEVEL(c)) {
28272826
VISIT(c, expr, value);
28282827
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
28292828
ADDOP(c, NO_LOCATION, POP_TOP);

Python/compile.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,17 +1204,12 @@ _PyCompile_OptimizationLevel(compiler *c)
12041204
}
12051205

12061206
int
1207-
_PyCompile_IsInteractive(compiler *c)
1208-
{
1209-
return c->c_interactive;
1210-
}
1211-
1212-
int
1213-
_PyCompile_IsNestedScope(compiler *c)
1207+
_PyCompile_IsInteractiveTopLevel(compiler *c)
12141208
{
12151209
assert(c->c_stack != NULL);
12161210
assert(PyList_CheckExact(c->c_stack));
1217-
return PyList_GET_SIZE(c->c_stack) > 0;
1211+
bool is_nested_scope = PyList_GET_SIZE(c->c_stack) > 0;
1212+
return c->c_interactive && !is_nested_scope;
12181213
}
12191214

12201215
int

0 commit comments

Comments
 (0)
0