Skip to content

pyrepl: Unable to ^D exit in multiline section #133400

Closed

Description

@StanFromIreland

Bug report

Bug description:

To reproduce, type ( an then enter a few times, you will be unable to exit via ^D unlike on a single prompt line (nothing happens).

In the PYTHON_BASIC_REPL ctrl-D exits the multiline section.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    on May 4, 2025
  2. sergey-miryanov commented on May 5, 2025

    @sergey-miryanov
    Contributor

    On windows for PYTHON_BASIC_REPL=1 I get following for 3.13.1 and for current main:

    Image

    Without PYTHON_BASIC_REPL it just swallows input.

  3. added 2 commits that reference this issue on May 11, 2025
  4. deepwzh commented on May 11, 2025

    @deepwzh
    Contributor

    Does this issue need to be fixed? If so,
    I tried to submit a PR, does anyone have time to review it?
    @tomasr8 @picnixz

  5. StanFromIreland commented on Jul 16, 2025

    @StanFromIreland
    MemberAuthor

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

  6. added a commit that references this issue on Jul 20, 2025
  7. deepwzh commented on Jul 30, 2025

    @deepwzh
    Contributor

    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 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.

  8. adqm commented on Jul 30, 2025

    @adqm
    Contributor

    For the record, I have a patch ready for code.interact that makes it match the behavior from @deepwzh's pyrepl PR.

  9. added 3 commits that reference this issue on Oct 9, 2025
  10. adqm commented on Oct 9, 2025

    @adqm
    Contributor

    Since #133883 was merged, I'll put in a PR for the code.interact issue later today.

  11. added 2 commits that reference this issue on Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions