Skip to content

New REPL - readline module does not save history with write_history_file #130938

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

Closed
devcode11 opened this issue Mar 7, 2025 · 3 comments
Closed
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@devcode11
Copy link

devcode11 commented Mar 7, 2025

Bug report

Bug description:

When using new REPL in Python 13, the readline module does not write history to the files correctly.
I have checked this issue on both my host system, as well as python:alpine container from docker.

Using PYTHON_BASIC_REPL=1 no longer causes this issue.

Expected
hist.txt file contains the saved commands.

Actual
hist.txt file is empty. Note that .python_history file does save and load history correctly.

/ # python -i
Python 3.13.2 (main, Feb 14 2025, 19:28:41) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> print('abc')
abc
>>> readline.get_current_history_length()
0
>>> readline.set_history_length(100)
>>> readline.get_current_history_length()
0
>>> readline.write_history_file('hist.txt')
>>> 
/ # cat hist.txt 
/ # cat ~/.python_history 
import readline
print('abc')
readline.get_current_history_length()
readline.set_history_length(100)
readline.get_current_history_length()
readline.write_history_file('hist.txt')
/ # 

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@devcode11 devcode11 added the type-bug An unexpected behavior, bug, or error label Mar 7, 2025
@skirpichev skirpichev added the topic-repl Related to the interactive shell label Mar 7, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Mar 7, 2025
@oedokumaci
Copy link

oedokumaci commented Mar 10, 2025

>>> readline.get_current_history_length()
0
>>> readline.set_history_length(100)
>>> readline.get_current_history_length()
0

set_history_length method sets the _ReadlineWrapper.saved_history_length attribute, which you can get by get_history_length not get_current_history_length

What is the readline version of your runtime? You can check by

import readline
readline._READLINE_LIBRARY_VERSION

@oedokumaci
Copy link

I digged a little further and It seems that when you do import readline despite CAN_USE_PYREPL flag being True it still imports the readline.c. The python implementation _pyrepl/readline.py is then never imported unless you reload the sys.modules. So the public api _wrapper = _ReadlineWrapper() of _pyrepl/readline.py is not being used.

If what I said is true and that it needs a fix, I can help if a core dev can point me in the right direction.

@ambv
Copy link
Contributor

ambv commented Apr 16, 2025

Closing as duplicate of #120766. We'll handle it.

@ambv ambv closed this as completed Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants