You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pyrepl: Unable to ^D exit in multiline section #133400
I'm not sure whether I would call this a bug per se, but I just noticed that code.interact() has different behavior from both the old and the new REPL when working with multiline input. When in multiline mode and hitting CTRL+D on a new, blank line, e.g.:
>>> def foo(x):
... [ctrl+d]
The old REPL (tested in Python 3.11) seems to run the input up to the EOF, leaving us in the REPL:
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x):
...
File "<stdin>", line 1
def foo(x):
^
IndentationError: expected an indented sensibleblock after function definition on line 1
In new REPL (testing in Python 3.13), it seems to be a NOP (we can still edit from here):
Python 3.13.1 (main, Feb 2 2025, 23:16:12) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x):
...
In code.interact(), though, it exits the REPL entirely, without running the code:
>>> code.interact()
Python 3.13.1 (main, Feb 2 2025, 23:16:12) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> def foo(x):
...
now exiting InteractiveConsole...
I could see arguments for any of those three behaviors being the "right" one, but regardless of what the right behavior is, it feels like code.interact and the Python REPL should have the same behavior here.
I'd be happy to have a go at a PR for this but am unsure what the most reasonable change is (or if this is even worth changing).
I'm not sure whether I would call this a bug per se, but I just noticed that code.interact() has different behavior from both the old and the new REPL when working with multiline input. When in multiline mode and hitting CTRL+D on a new, blank line, e.g.:
>>> def foo(x):
... [ctrl+d]
The old REPL (tested in Python 3.11) seems to run the input up to the EOF, leaving us in the REPL:
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x):
...
File "<stdin>", line 1
def foo(x):
^
IndentationError: expected an indented sensibleblock after function definition on line 1
In new REPL (testing in Python 3.13), it seems to be a NOP (we can still edit from here):
Python 3.13.1 (main, Feb 2 2025, 23:16:12) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x):
...
In code.interact(), though, it exits the REPL entirely, without running the code:
>>> code.interact()
Python 3.13.1 (main, Feb 2 2025, 23:16:12) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> def foo(x):
...
now exiting InteractiveConsole...
I could see arguments for any of those three behaviors being the "right" one, but regardless of what the right behavior is, it feels like code.interact and the Python REPL should have the same behavior here.
I'd be happy to have a go at a PR for this but am unsure what the most reasonable change is (or if this is even worth changing).
CPython versions tested on:
3.11, 3.13
Operating systems tested on:
No response
@StanFromIreland
I have completed the fixes for the related issues in the new REPL. You can test them to see if they work. Also, if the tests pass, do you have the permission to merge the code?
Regarding code.interact, I noticed that it's a more simplified implementation compared to pyprel. I think it might need to be addressed as a new issue, and the relevant maintainers can decide whether to implement it.
Activity
sergey-miryanov commentedon May 5, 2025
On windows for
PYTHON_BASIC_REPL=1I get following for 3.13.1 and for current main:Without
PYTHON_BASIC_REPLit just swallows input.pythongh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module
pythongh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module
deepwzh commentedon May 11, 2025
Does this issue need to be fixed? If so,
I tried to submit a PR, does anyone have time to review it?
@tomasr8 @picnixz
code.interactand Python REPL #136730 as a duplicate of this issueStanFromIreland commentedon Jul 16, 2025
Useful information from duplicate:
I'm not sure whether I would call this a bug per se, but I just noticed that
code.interact()has different behavior from both the old and the new REPL when working with multiline input. When in multiline mode and hittingCTRL+Don a new, blank line, e.g.:The old REPL (tested in Python 3.11) seems to run the input up to the EOF, leaving us in the REPL:
In new REPL (testing in Python 3.13), it seems to be a NOP (we can still edit from here):
In
code.interact(), though, it exits the REPL entirely, without running the code:I could see arguments for any of those three behaviors being the "right" one, but regardless of what the right behavior is, it feels like
code.interactand the Python REPL should have the same behavior here.I'd be happy to have a go at a PR for this but am unsure what the most reasonable change is (or if this is even worth changing).
CPython versions tested on:
3.11, 3.13
Operating systems tested on:
No response
pythongh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module
deepwzh commentedon Jul 30, 2025
@StanFromIreland
I have completed the fixes for the related issues in the new REPL. You can test them to see if they work. Also, if the tests pass, do you have the permission to merge the code?
Regarding
code.interact, I noticed that it's a more simplified implementation compared topyprel. I think it might need to be addressed as a new issue, and the relevant maintainers can decide whether to implement it.adqm commentedon Jul 30, 2025
For the record, I have a patch ready for
code.interactthat makes it match the behavior from @deepwzh's pyrepl PR.gh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module (GH-13…
[3.14] pythongh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` …
[3.13] pythongh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` …
adqm commentedon Oct 9, 2025
Since #133883 was merged, I'll put in a PR for the
code.interactissue later today.[3.13] gh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module (…
[3.14] gh-133400: Fixed Ctrl+D (^D) behavior in :mod:`_pyrepl` module (…