Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions Lib/_pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,9 @@ 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"
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":
Expand Down
11 changes: 10 additions & 1 deletion Lib/test/test_pyrepl/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ def test_multiple_statements_output(self):
with contextlib.redirect_stdout(f):
more = console.push(code, filename="<stdin>", _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="<stdin>")
f = io.StringIO()
with contextlib.redirect_stdout(f):
more = console.push(code, filename="<stdin>", _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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix new repl to display output from multiple statements, separated by ';'.
Patch by Sergey B Kirpichev.
Loading