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:
Pablo Galindo Salgado 2024-05-07 17:01:49 +01:00 committed by GitHub
parent 26bab423fb
commit a94ac56628
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 33 additions and 9 deletions

View file

@ -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: