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

'\040' instead of space in repl history on macOS with 3.13 or main branch #119310

Open
aisk opened this issue May 21, 2024 · 2 comments
Open

'\040' instead of space in repl history on macOS with 3.13 or main branch #119310

aisk opened this issue May 21, 2024 · 2 comments
Assignees
Labels
3.13 bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@aisk
Copy link
Contributor

aisk commented May 21, 2024

Bug report

Bug description:

When using the version of Python (3.9.6) that comes with Apple at /usr/bin/python, or when installing the latest version of Python (3.12.3) via Homebrew, the readline functionality is based on libedit. There is a file ~/.python_history that stores the REPL history, and its content is similar to:

_HiStOrY_V2_
import\040os

When using the latest version of Python built from the main branch, which includes the new REPL, pressing the up arrow key will display:

❯ ./python.exe
Python 3.14.0a0 experimental free-threading build (heads/main:73f4a58d36, May 21 2024, 21:12:51) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import\040os

The '\04' is not converted to space character.

CPython versions tested on:

3.13

Operating systems tested on:

macOS Sonoma 14.2

Linked PRs

@aisk aisk added type-bug An unexpected behavior, bug, or error topic-repl Related to the interactive shell 3.13 bugs and security fixes labels May 21, 2024
@ambv
Copy link
Contributor

ambv commented May 21, 2024

That's because editline used by the basic REPL. We'll address this in the betas.

@Constantin1489
Copy link
Contributor

Constantin1489 commented May 21, 2024

See also, #102130 (comment) (may ignore some of my argument in the url. But take the examples or links or symptoms. The handling for encoding part in my example code is just wrong.)

it looks like the problem is deeper than thought...

# print_all_printable_unicode.py
# https://stackoverflow.com/a/77352299/20307768
for i in range(0x0000, 1 + 0xffff, 1):
    if str.isprintable(chr(i)):
        print(chr(i))
  1. backup the ~/.python_history
    mv ~/.python_history ~/.python_history.bak
  2. initialize editline history files with its header
    echo "_HiStOrY_V2_" > ~/.python_history > ~/.python_history.utf8
  3. run the code and redirect output to files.
    python print_all_printable_unicode.py >> ~/.python_history >> ~/.python_history.utf8
  4. run python repl with editline and exit (It will modify ~/.python_history)
    python
  5. compare result using vim(diff)
    vim -d ~/.python_history ~/.python_history.utf8

aorcajo added a commit to aorcajo/cpython that referenced this issue Jul 16, 2024
@ambv ambv self-assigned this Sep 5, 2024
ambv added a commit that referenced this issue Sep 6, 2024
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 6, 2024
…-121779)

(cherry picked from commit e959848)

Co-authored-by: aorcajo <589252+aorcajo@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
ambv added a commit that referenced this issue Sep 6, 2024
…) (#123784)

(cherry picked from commit e959848)

Co-authored-by: aorcajo <589252+aorcajo@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants