astral-sh / astral-sh/python-build-standalone
`readline.set_history_length` results in unreadable history files
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 314
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 27
Description
Hello,
Writing a history file after a call to `readline.set_history_length` results in an unreadable history file. For example, with `cpython-3.12.4+20240713-x86_64-unknown-linux-gnu-install_only.tar.gz`:
```py
import readline
import os
readline.add_history("first line")
readline.add_history("second line")
readline.add_history("third line")
readline.set_history_length(2)
readline.write_history_file('historyfile.tmp')
try:
readline.read_history_file('historyfile.tmp')
finally:
os.remove('historyfile.tmp')
```
gives me a traceback on the `read_history_file`:
```
Traceback (most recent call last):
File "/script.py", line 12, in
readline.read_history_file('historyfile.tmp')
OSError: [Errno 22] Invalid argument
```
This might be a conflict/incompatibility between editline and a history library that doesn't work with editline's `_HiStOrY_V2_` format.
I've [added a test to CPython](https://github.com/python/cpython/pull/121326) that should fail in this case. I don't know what more I can do on the CPython side.
The same “Invalid argument” error happens when trying to read a history file produced with GNU readline. This can affect users switching from some earlier standalone builds.
Contributor guide
Research direction
Run the Python reproduction in the issue and compare history files produced after readline.set_history_length with files from GNU readline and editline. Review the linked CPython test pull request for the expected round-trip behavior; done means the standalone build can write and read the affected history files without OSError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100