diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py
index 7916638921bbf2..e6719491f1404d 100644
--- a/Lib/_pyrepl/console.py
+++ b/Lib/_pyrepl/console.py
@@ -201,11 +201,9 @@ def runsource(self, source, filename="", 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"
- item = wrapper([stmt])
+ item = ast.Interactive([stmt])
try:
- code = self.compile.compiler(item, filename, the_symbol)
+ code = self.compile.compiler(item, filename, symbol)
linecache._register_code(code, source, filename)
except SyntaxError as e:
if e.args[0] == "'await' outside function":
diff --git a/Lib/test/test_pyrepl/test_interact.py b/Lib/test/test_pyrepl/test_interact.py
index c3204832a6a93a..a278152d5c4b09 100644
--- a/Lib/test/test_pyrepl/test_interact.py
+++ b/Lib/test/test_pyrepl/test_interact.py
@@ -51,7 +51,16 @@ def test_multiple_statements_output(self):
with contextlib.redirect_stdout(f):
more = console.push(code, filename="", _symbol="single") # type: ignore[call-arg]
self.assertFalse(more)
- self.assertEqual(f.getvalue(), "1\n")
+ self.assertEqual(f.getvalue(), "1\n1\n")
+
+ namespace = {}
+ code = "'foo';'bar'"
+ console = InteractiveColoredConsole(namespace, filename="")
+ f = io.StringIO()
+ with contextlib.redirect_stdout(f):
+ more = console.push(code, filename="", _symbol="single") # type: ignore[call-arg]
+ self.assertFalse(more)
+ self.assertEqual(f.getvalue(), "'foo'\n'bar'\n")
@force_not_colorized
def test_multiple_statements_fail_early(self):
diff --git a/Misc/NEWS.d/next/Library/2025-03-17-12-03-32.gh-issue-131217.ejHRzN.rst b/Misc/NEWS.d/next/Library/2025-03-17-12-03-32.gh-issue-131217.ejHRzN.rst
new file mode 100644
index 00000000000000..21f36c94f4c529
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-03-17-12-03-32.gh-issue-131217.ejHRzN.rst
@@ -0,0 +1,2 @@
+Fix new repl to display output from multiple statements, separated by ';'.
+Patch by Sergey B Kirpichev.