python / python/cpython

New REPL crashes on an empty DELETE_WORD_BACKWARDS (^W) followed by CLEAR_TO_START (^K)

Open
#131,430 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug report

Bug description:

If, in the REPL, you:

  1. Delete the current word, backward, on an empty line using Control-W, then
  2. Delete to the end of line, using Control-K

The REPL will crash with an exception in readline.

Note: ^ denotes pressing the Control or Command key when pressing the next character.

>>> ^W^KTraceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib64/python3.13/_pyrepl/__main__.py", line 6, in <module>
    __pyrepl_interactive_console()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.13/_pyrepl/main.py", line 59, in interactive_console
    run_multiline_interactive_console(console)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib64/python3.13/_pyrepl/simple_interact.py", line 143, in run_multiline_interactive_console
    statement = multiline_input(more_lines, ps1, ps2)
  File "/usr/lib64/python3.13/_pyrepl/readline.py", line 389, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.13/_pyrepl/reader.py", line 802, in readline
    self.handle1()
    ~~~~~~~~~~~~^^
  File "/usr/lib64/python3.13/_pyrepl/reader.py", line 785, in handle1
    self.do_cmd(cmd)
    ~~~~~~~~~~~^^^^^
  File "/usr/lib64/python3.13/_pyrepl/reader.py", line 710, in do_cmd
    command.do()
    ~~~~~~~~~~^^
  File "/usr/lib64/python3.13/_pyrepl/commands.py", line 157, in do
    self.kill_range(r.pos, eol + 1)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/_pyrepl/commands.py", line 71, in kill_range
    r.kill_ring[-1] = r.kill_ring[-1] + text
                      ~~~~~~~~~~~^^^^

This exception is caused since kill_range is not called on an empty backward_kill_word, causing kill_ring to be empty: https://github.com/pypy/pyrepl/blob/ca192a80b76700118b9bfd261a3d098b92ccfc31/pyrepl/commands.py#L152-L156

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-131452

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 in pyrepl/commands.py around lines 152-156, where backward word deletion and kill_range are described. Reproduce the empty-line ^W followed by ^K sequence in the REPL and trace the kill-ring state. Done means the sequence no longer raises the reported readline exception; linked PR gh-131452 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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.