Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13+ REPL inserts ~ on [Del] [PgUp] [PgDn] with TERM=vt100 #124027

Closed
hroncok opened this issue Sep 12, 2024 · 2 comments · Fixed by #124028
Closed

Python 3.13+ REPL inserts ~ on [Del] [PgUp] [PgDn] with TERM=vt100 #124027

hroncok opened this issue Sep 12, 2024 · 2 comments · Fixed by #124028
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@hroncok
Copy link
Contributor

hroncok commented Sep 12, 2024

Bug report

Bug description:

I've noticed that the Python 3.13+ REPL misbehaves in a mock shell environment. Whenever I press Del, PgUp, or PgDn, a literal ~ character is inserted.

tl;dr this happens when you run TERM=vt100 python3.13.

Details:

I did not know what was special about the mock shell, but this did not happen with the old readline-based REPL.

When trying to figure out what's different in the mock shell I looked at env and it was:

SHELL=/bin/bash
HISTCONTROL=ignoredups
HISTSIZE=1000
HOSTNAME=2f26bd11c076
PWD=/builddir
LOGNAME=root
HOME=/builddir
LANG=C.UTF-8
LS_COLORS=...snip...
PROMPT_COMMAND=printf "\033]0;<mock-chroot>\007"
TERM=vt100
USER=root
SHLVL=1
PS1=<mock-chroot> \s-\v\$ 
DEBUGINFOD_URLS=https://debuginfod.fedoraproject.org/ 
PATH=/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
MAIL=/var/spool/mail/root
_=/usr/bin/env

I found out that to reproduce, all I have to do is to set TERM=vt100. I don't know the actual meaning of that, but it changes the behavior of the new REPL, but not the old.

$ TERM=vt100 python3.13
Python 3.13.0rc2 (main, Sep  7 2024, 00:00:00) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Pressing either of Del, PgUp, or PgDn (possibly other keys?) adds a literal ~ instead of doing any of the expected actions (history traverse up, down, deleting the next character if any).

$ TERM=vt100 python3.12
Python 3.12.6 (main, Sep  9 2024, 00:00:00) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Pressing either of Del, PgUp, or PgDn does what it is supposed to do.


To reproduce my actual use case, first install mock. The easiest way is to use podman (or docker) with Fedora. Following https://rpm-software-management.github.io/mock/#mock-inside-podman-fedora-toolbox-or-docker-container

$ podman run --rm --privileged -ti fedora:40 bash  # or docker run --cap-add=SYS_ADMIN ...
# dnf install -y mock
# useradd mockbuilder
# usermod -a -G mock mockbuilder
# su - mockbuilder
$ mock -r fedora-rawhide-x86_64 --no-bootstrap-image install python3.13 python3.12
...
$ mock -r fedora-rawhide-x86_64 shell
...
<mock-chroot> sh-5.2# python3.13
Python 3.13.0rc2 (main, Sep  7 2024, 00:00:00) [GCC 14.2.1 20240905 (Red Hat 14.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

@hroncok hroncok added the type-bug An unexpected behavior, bug, or error label Sep 12, 2024
@JelleZijlstra JelleZijlstra added the topic-repl Related to the interactive shell label Sep 12, 2024
@hroncok
Copy link
Contributor Author

hroncok commented Sep 12, 2024

I think this might be a ncurses thing. Trying to figure out which one... but it's getting late.

@hroncok
Copy link
Contributor Author

hroncok commented Sep 13, 2024

Adding this keymap entry solves the delete case:

(r"\x1b[3~", "delete"),

hroncok added a commit to hroncok/cpython that referenced this issue Sep 13, 2024
From Fedora's /etc/inputrc:

    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    "\e[3~": delete-char

Fixes python#124027
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 13, 2024
…124028)

pyrepl: Support Del, PgUp, and PgDn on TERM=vt100

From Fedora's /etc/inputrc:

    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    "\e[3~": delete-char

Fixes python#124027
(cherry picked from commit f4e5643)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
pablogsal pushed a commit that referenced this issue Sep 13, 2024
… (#124029)

gh-124027: Support Del, PgUp, and PgDn on TERM=vt100 (GH-124028)

pyrepl: Support Del, PgUp, and PgDn on TERM=vt100

From Fedora's /etc/inputrc:

    "\e[5~": history-search-backward
    "\e[6~": history-search-forward
    "\e[3~": delete-char

Fixes #124027
(cherry picked from commit f4e5643)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants