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
Since the libedit transition (correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions related to history files are broken.
It is inconvenient enough that history files written by GNU readline based readline module are unreadable and result in a rather confusing OSError with exc.errno == errno.EINVAL (without a corresponding operating system routine that returns such an error), but a workaround intercepting this OSError can be written that converts the old format to the new one. This has been covered before, e.g. in The New REPL Does Not Load My Command History #120766.
More importantly, history files written by libedit based readline module are unreadable by itself when set_history_length is used, as demonstrated by the code below.
While a workaround for that is also possible (also below), as far as I can tell, until 3.13, so until a year from now (?) (whenever Add readline.backend for the backend readline uses #112510 becomes available in a release), your only option is "libedit" in readline.__doc__, which I expect will be what many people will leave in the codebase even once readline.backend becomes available.
Reproducer:
importreadlinereadline.add_history("foo bar")
readline.add_history("nope nope")
readline.write_history_file("history-works")
# this works:readline.read_history_file("history-works")
readline.set_history_length(2)
readline.write_history_file("history-breaks")
# this breaks:readline.read_history_file("history-breaks")
Bug report
Bug description:
Since the libedit transition(correction: If an end user switches from a GNU readline build of Python to an editline build of Python), several important functions related to history files are broken.readlinemodule are unreadable and result in a rather confusingOSErrorwithexc.errno == errno.EINVAL(without a corresponding operating system routine that returns such an error), but a workaround intercepting thisOSErrorcan be written that converts the old format to the new one. This has been covered before, e.g. in The New REPL Does Not Load My Command History #120766.readlinemodule are unreadable by itself whenset_history_lengthis used, as demonstrated by the code below.readline.backendfor the backendreadlineuses #112510 becomes available in a release), your only option is"libedit" in readline.__doc__, which I expect will be what many people will leave in the codebase even oncereadline.backendbecomes available.Reproducer:
Workaround:
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs