Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Sep 13, 2024

@JelleZijlstra
Copy link
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
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
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
Python/compile.c Outdated
@@ -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?

@JelleZijlstra JelleZijlstra merged commit 9aa1f60 into python:main Sep 16, 2024
37 checks passed
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