From 5e94fa4162f837fedb8856bfb511a765f4687a49 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Fri, 15 Sep 2017 22:36:56 -0400 Subject: [PATCH] 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. --- Doc/library/readline.rst | 4 ++-- .../Documentation/2017-10-08-23-02-14.bpo-31537.SiFNM8.rst | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2017-10-08-23-02-14.bpo-31537.SiFNM8.rst diff --git a/Doc/library/readline.rst b/Doc/library/readline.rst index 54c54b461ce7e4..837816e952ad56 100644 --- a/Doc/library/readline.rst +++ b/Doc/library/readline.rst @@ -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) diff --git a/Misc/NEWS.d/next/Documentation/2017-10-08-23-02-14.bpo-31537.SiFNM8.rst b/Misc/NEWS.d/next/Documentation/2017-10-08-23-02-14.bpo-31537.SiFNM8.rst new file mode 100644 index 00000000000000..9244d7ee627ed2 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2017-10-08-23-02-14.bpo-31537.SiFNM8.rst @@ -0,0 +1,2 @@ +Fix incorrect usage of ``get_history_length`` in readline documentation +example code. Patch by Brad Smith.