8000 bpo-31537: Fix bug in readline documentation example code · python/cpython@5e94fa4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e94fa4

Browse files
committed
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.
1 parent 4d3f084 commit 5e94fa4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Doc/library/readline.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ sessions, by only appending the new history. ::
312312

313313
try:
314314
readline.read_history_file(histfile)
315-
h_len = readline.get_history_length()
315+
h_len = readline.get_current_history_length()
316316
except FileNotFoundError:
317317
open(histfile, 'wb').close()
318318
h_len = 0
319319

320320
def save(prev_h_len, histfile):
321-
new_h_len = readline.get_history_length()
321+
new_h_len = readline.get_current_history_length()
322322
readline.set_history_length(1000)
323323
readline.append_history_file(new_h_len - prev_h_len, histfile)
324324
atexit.register(save, h_len, histfile)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix incorrect usage of ``get_history_length`` in readline documentation
2+
example code. Patch by Brad Smith.

0 commit comments

Comments
 (0)
0