You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New REPL - readline module does not save history with write_history_file #130938
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')
/ #
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
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.
Activity
oedokumaci commentedon Mar 10, 2025
set_history_lengthmethod sets the_ReadlineWrapper.saved_history_lengthattribute, which you can get byget_history_lengthnotget_current_history_lengthWhat is the readline version of your runtime? You can check by
oedokumaci commentedon Mar 10, 2025
I digged a little further and It seems that when you do
import readlinedespiteCAN_USE_PYREPLflag beingTrueit still imports thereadline.c. The python implementation_pyrepl/readline.pyis then never imported unless you reload thesys.modules. So the public api_wrapper = _ReadlineWrapper()of_pyrepl/readline.pyis 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 commentedon Apr 16, 2025
Closing as duplicate of #120766. We'll handle it.