mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-111201: Allow pasted code to contain multiple statements in the REPL (#118712)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
26bab423fb
commit
a94ac56628
6 changed files with 33 additions and 9 deletions
|
@ -135,7 +135,7 @@ def run_multiline_interactive_console(
|
|||
ps1 = getattr(sys, "ps1", ">>> ")
|
||||
ps2 = getattr(sys, "ps2", "... ")
|
||||
try:
|
||||
statement = multiline_input(more_lines, ps1, ps2)
|
||||
statement, contains_pasted_code = multiline_input(more_lines, ps1, ps2)
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
|
@ -144,7 +144,10 @@ def run_multiline_interactive_console(
|
|||
|
||||
input_name = f"<python-input-{input_n}>"
|
||||
linecache._register_code(input_name, statement, "<stdin>") # type: ignore[attr-defined]
|
||||
more = console.push(_strip_final_indent(statement), filename=input_name) # type: ignore[call-arg]
|
||||
symbol = "single" if not contains_pasted_code else "exec"
|
||||
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol=symbol) # type: ignore[call-arg]
|
||||
if contains_pasted_code and more:
|
||||
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
|
||||
assert not more
|
||||
input_n += 1
|
||||
except KeyboardInterrupt:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue