Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

readline.set_history_length corrupts history files when used in a libedit build #121160

Closed
Labels
topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error
@whitequark

Description

@whitequark

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.

  1. It is inconvenient enough that history files written by GNU readline basedreadline module are unreadable and result in a rather confusingOSError withexc.errno == errno.EINVAL (without a corresponding operating system routine that returns such an error), but a workaround intercepting thisOSError can be written that converts the old format to the new one. This has been covered before, e.g. inThe New REPL Does Not Load My Command History #120766.
  2. More importantly, history files written by libedit basedreadline module are unreadable by itself whenset_history_length is used, as demonstrated by the code below.
  3. 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 (?) (wheneverAddreadline.backend for the backendreadline 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 oncereadline.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")

Workaround:

def_is_using_libedit():ifhasattr(readline,"backend"):returnreadline.backend=="editline"else:return"libedit"inreadline.__doc__readline.set_history_length(1000)if_is_using_libedit():readline.replace_history_item(max(0,readline.get_current_history_length()-readline.get_history_length()),"_HiStOrY_V2_")

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp