Skip to content

REPL import tab completion moves cursor backward #145448

Description

@injust

Bug report

Bug description:

When tab completing ambiguous imports in the Python REPL, pressing tab once will insert the longest unambiguous completion and display "[ complete but not unique ]". Pressing tab a second time will show all the possibilities.

In Ghostty, when you press tab the second time, the cursor moves one cell to the left. This happens with cursor-style = bar as well as the default block cursor.

I reproduced this in Ghostty with both fish shell and bash. I could not reproduce this in Zed's integrated terminal (with a bar cursor) or Terminal.app (with a block cursor).

Originally posted by @injust in ghostty-org/ghostty#11131


I initially reported this issue to Ghostty, and the maintainer's response was:

This is a bug in Terminal.app in how it handles CUB with the cursor in the pending wrap state. Or, a bug in Python's readline in how it calculates the amount to move the cursor back. Your bug reproduces on xterm, and Ghostty matches xterm. Specifically, CUB moves exactly n cells back ignoring pending wrap in xterm and Ghostty matches this. In Terminal.app, CUB subtracts one when it is in the pending wrap state.

Since the bug reproduces in both Ghostty and xterm, it might be a bug in the Python REPL.

I captured the bug in this asciicast: https://github.com/user-attachments/files/25683940/ascii.cast.json

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Mar 3, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 3, 2026
  3. StanFromIreland commented on Mar 3, 2026

    @StanFromIreland
    Member

    I cannot reproduce this with ptyxis on Linux.

  4. added
    pendingThe issue will be closed if no feedback is provided
    on Mar 3, 2026
  5. added a commit that references this issue on Mar 10, 2026
  6. mvanhorn commented on Mar 10, 2026

    @mvanhorn
    Contributor

    I've submitted a fix in PR #145727. The issue was that posxy in unix_console.py recorded the cursor at width when it was actually at width-1 in pending wrap state, causing CUB to overshoot by one cell.

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

    pendingThe issue will be closed if no feedback is providedstdlibStandard 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