◐ Shell
clean mode source ↗

Editing the last line in a block in the new REPL is buggy

Bug report

Bug description:

When editing the last line in a function in the new REPL, hitting Enter doesn't end the block if the last line has indentation on it.

658451

Demo of the bug, demo of what IPython does

Originally posted in #111201 (comment)

Here are the noticeable differences in how IPython handles this situation:

  1. When hitting the up arrow key to edit the block, the final blank line isn't included (the default cursor position is at the end of the last non-empty line.

image

  1. In IPython I tried purposely adding extra whitespace-only lines (not fully blank but instead containing 4 spaces) by hitting Enter, up arrow, End, Enter, up arrow, End, repeatedly. If I then hit Enter on the first line-followed-by-whitespace-only-lines it ends the block.

image

  1. Hitting up arrow again, will strip whitespace from the end of the block (maybe this is how 1 above is implemented)

image

Implementing the behavior of 1 (or 3) above might be enough, though 2 seems like it would be even better.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs