Skip to content
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

New repl shows output only for last statement from several, separated by ";" #131217

Open
skirpichev opened this issue Mar 14, 2025 · 4 comments
Open
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Member

skirpichev commented Mar 14, 2025

Bug report

Bug description:

An example:

$ python3.13
Python 3.13.1 (tags/v3.13.1:0671451779, Dec  4 2024, 07:55:26) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1;2
2
$ PYTHON_BASIC_REPL=1 python3.13
Python 3.13.1 (tags/v3.13.1:0671451779, Dec  4 2024, 07:55:26) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1;2
1
2

That's valid for the current main.

A lot of docstrings in the mpmath rely on this feature of old repl. So, this looks as a bug for me.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@skirpichev skirpichev added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error labels Mar 14, 2025
@skirpichev skirpichev changed the title New repl show output only for last statement from several, separated by ";" New repl shows output only for last statement from several, separated by ";" Mar 14, 2025
@skirpichev
Copy link
Member Author

Following "works for me":

diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py
index 7916638921..256edc07a0 100644
--- a/Lib/_pyrepl/console.py
+++ b/Lib/_pyrepl/console.py
@@ -201,8 +201,8 @@ def runsource(self, source, filename="<input>", symbol="single"):
         if tree.body:
             *_, last_stmt = tree.body
         for stmt in tree.body:
-            wrapper = ast.Interactive if stmt is last_stmt else ast.Module
-            the_symbol = symbol if stmt is last_stmt else "exec"
+            wrapper = ast.Interactive  # if stmt is last_stmt else ast.Module
+            the_symbol = symbol  # if stmt is last_stmt else "exec"
             item = wrapper([stmt])
             try:
                 code = self.compile.compiler(item, filename, the_symbol)
$ ./python -m test test_repl -u curses
Using random seed: 3945173947
0:00:00 load avg: 0.97 Run 1 test sequentially in a single process
0:00:00 load avg: 0.97 [1/1] test_repl
0:00:03 load avg: 0.97 [1/1] test_repl passed

== Tests result: SUCCESS ==

1 test OK.

Total duration: 3.2 sec
Total tests: run=13
Total test files: run=1/1
Result: SUCCESS

@terryjreedy
Copy link
Member

In IDLE on main, which also uses code.InteractiveInterpreter but with a simpler runsource override:

>>> 1; 2
1
2

@skirpichev
Copy link
Member Author

Yes, that works fine in the mpmath repl, which uses code.InteractiveConsole.

@picnixz picnixz added the stdlib Python modules in the Lib dir label Mar 14, 2025
skirpichev added a commit to skirpichev/cpython that referenced this issue Mar 17, 2025
…ed by ';'

Was:
```pycon
>>> 1;2
2
```

Now:
```pycon
>>> 1;2
1
2
```
@skirpichev
Copy link
Member Author

skirpichev commented Mar 17, 2025

pr is ready: #131341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants