python / python/cpython

Difference in Ctrl+D Behavior Between REPL and `code.interact`

Open
#139,875 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

With #133883 merged, hitting ctrl+d at the start of a blank line in a multi-line entry causes the existing code to be evaluated in both the new REPL and the basic REPL:

>>> def foo(x):
... 
  File "<python-input-0>", line 1
    def foo(x):
               ^
IndentationError: expected an indented block after function definition on line 1

But code.interact() exits immediately without executing the existing code:

>>> def foo(x):
... 

now exiting InteractiveConsole...

I doubt this is terribly impactful, but I think it would still be nice to have these behave the same way.

I have a patch ready that I think will resolve this, so I'll open a PR shortly.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-139876

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing Ctrl+D handling in the new and basic REPL with code.interact(), using the blank-line multi-line function definition reproduction in the issue. Done means code.interact() evaluates the existing code consistently with the other REPLs; linked PR gh-139876 indicates work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.