Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ 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_IsInInlinedComp(struct _PyCompiler *c);
int _PyCompile_ScopeType(struct _PyCompiler *c);
int _PyCompile_OptimizationLevel(struct _PyCompiler *c);
Expand Down
3 changes: 1 addition & 2 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ typedef struct _PyCompiler compiler;
#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 SCOPE_TYPE(C) _PyCompile_ScopeType(C)
#define QUALNAME(C) _PyCompile_Qualname(C)
#define METADATA(C) _PyCompile_Metadata(C)
Expand Down Expand Up @@ -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(c)) {
VISIT(c, expr, value);
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
ADDOP(c, NO_LOCATION, POP_TOP);
Expand Down
9 changes: 2 additions & 7 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,16 +1205,11 @@ _PyCompile_OptimizationLevel(compiler *c)

int
_PyCompile_IsInteractive(compiler *c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming this to something like _PyCompile_IsInteractiveTopLevel for clarity?

{
return c->c_interactive;
}

int
_PyCompile_IsNestedScope(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
Expand Down
Loading