Skip to content

gh-124058: remove _PyCompile_IsNestedScope, roll it into _PyCompile_IsInteractive#124061

Merged
JelleZijlstra merged 5 commits into
python:mainfrom
iritkatriel:move_interactive
Sep 16, 2024
Merged

gh-124058: remove _PyCompile_IsNestedScope, roll it into _PyCompile_IsInteractive#124061
JelleZijlstra merged 5 commits into
python:mainfrom
iritkatriel:move_interactive

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Sep 13, 2024

Copy link
Copy Markdown
Member

@JelleZijlstra

Copy link
Copy Markdown
Member
jelle@m3mb-jelle cpython % ./python.exe         
Python 3.14.0a0 (heads/move_interactive:cebdf71c554, Sep 13 2024, 09:10:41) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1; 2Assertion failed: (asdl_seq_LEN(stmts) == 1), function codegen_interactive, file codegen.c, line 748.
                                                                                                             zsh: abort      ./python.exe

This doesn't work correctly if there are multiple statements in one interactive.

@iritkatriel

Copy link
Copy Markdown
Member Author

I don't get it:

>>> dis.dis(compile("1;2", "", "single"))
  0           RESUME                   0

  1           LOAD_CONST               0 (1)
              CALL_INTRINSIC_1         1 (INTRINSIC_PRINT)
              POP_TOP
              LOAD_CONST               1 (2)
              CALL_INTRINSIC_1         1 (INTRINSIC_PRINT)
              POP_TOP
              RETURN_CONST             2 (None)
>>> 1;2
2

how come the 1 is not printed?

@iritkatriel

Copy link
Copy Markdown
Member Author

I don't get it:

>>> dis.dis(compile("1;2", "", "single"))
  0           RESUME                   0

  1           LOAD_CONST               0 (1)
              CALL_INTRINSIC_1         1 (INTRINSIC_PRINT)
              POP_TOP
              LOAD_CONST               1 (2)
              CALL_INTRINSIC_1         1 (INTRINSIC_PRINT)
              POP_TOP
              RETURN_CONST             2 (None)
>>> 1;2
2

how come the 1 is not printed?

This does print the 1:

>>> exec(compile("1;2", "", "single"))
1
2

so at the prompt we're doing something else.

@iritkatriel iritkatriel marked this pull request as draft September 13, 2024 20:54
@iritkatriel iritkatriel changed the title gh-124058: remove c_interactive from the compiler struct gh-124058: remove _PyCompile_IsNestedScope, roll it into _PyCompile_IsInteractive Sep 14, 2024
@iritkatriel iritkatriel marked this pull request as ready for review September 14, 2024 18:17
Comment thread Python/compile.c Outdated
@@ -1205,16 +1205,11 @@ _PyCompile_OptimizationLevel(compiler *c)

int
_PyCompile_IsInteractive(compiler *c)

Copy link
Copy Markdown
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?

@JelleZijlstra JelleZijlstra merged commit 9aa1f60 into python:main Sep 16, 2024
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this pull request Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove _PyCompile_IsNestedScope roll it into _PyCompile_IsInteractive

2 participants