8000 bpo-31537: Fix bug in readline documentation example code by infinitewarp · Pull Request #3925 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-31537: Fix bug in readline documentation example code #3925

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

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-31537: Fix bug in readline documentation example code
Use `get_current_history_length` to get the current length of the history,
not `get_history_length`. This fixes an issue where the example code's
call to `append_history_file` in the `save` function would never actually
write any lines to the file.
  • Loading branch information
infinitewarp committed Oct 9, 2017
commit 5e94fa4162f837fedb8856bfb511a765f4687a49
4 changes: 2 additions & 2 deletions Doc/library/readline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ sessions, by only appending the new history. ::

try:
readline.read_history_file(histfile)
h_len = readline.get_history_length()
h_len = readline.get_current_history_length()
except FileNotFoundError:
open(histfile, 'wb').close()
h_len = 0

def save(prev_h_len, histfile):
new_h_len = readline.get_history_length()
new_h_len = readline.get_current_history_length()
readline.set_history_length(1000)
readline.append_history_file(new_h_len - prev_h_len, histfile)
atexit.register(save, h_len, histfile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrect usage of ``get_history_length`` in readline documentation
example code. Patch by Brad Smith.
0