[issue31537] Bug in readline module documentation example
New submission from bazwal: The second example in the readline module docs uses readline.get_history_length() (lines 8 & 14) where it should use readline.get_current_history_length(). ---------- assignee: docs@python components: Documentation messages: 302655 nosy: bazwal, docs@python priority: normal severity: normal status: open title: Bug in readline module documentation example type: behavior versions: Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Change by Bradley Smith <brad82@gmail.com>: ---------- keywords: +patch pull_requests: +3898 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Bradley Smith <brad82@gmail.com> added the comment: I ran into the same bug in the documentation recently. I've opened a pull request here that fixes it: https://github.com/python/cpython/pull/3925 As I was trying to figure out why the example was broken, I wrote up a little more context to explain the current behavior and the fix: https://docs.python.org/3.7/library/readline.html#example https://docs.python.org/3.6/library/readline.html#example In the "Example" section, the second example that "supports concurrent interactive sessions, by only appending the new history" will actually *never* write any lines to a custom history file. This is conveniently masked by the fact that the file path used in the example code also happens to be the default path that readline automatically writes history to, but if you specify *any* other file path, you will see that the new file is created but never has any content written to it. The problem in this example is the use of `get_history_length` to get "previous" and "current" history lengths for determining how many lines to append to the file. Both calls to `get_history_length` always return `-1` here. Thus, when `append_history_file` is called, it always receives a first argument of `0` (because `-1 - -1 == 0`), resulting in zero lines written to the file. Instead of `get_history_length`, the example code *should* call `get_current_history_length`. Swapping that function call makes the example behave as expected, appending new lines to the file. ---------- nosy: +infinitewarp _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Mariatta Wijaya <mariatta.wijaya@gmail.com> added the comment: New changeset eeb5ffd54e56dd89a99c74eb512c36d62649cfec by Mariatta (Brad Smith) in branch 'master': bpo-31537: Update readline documentation example. (GH-3925) https://github.com/python/cpython/commit/eeb5ffd54e56dd89a99c74eb512c36d6264... ---------- nosy: +Mariatta _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- pull_requests: +3923 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Mariatta Wijaya <mariatta.wijaya@gmail.com> added the comment: New changeset 10eb14e2c5fe08c4193668530eaef156e07c3674 by Mariatta (Miss Islington (bot)) in branch '3.6': bpo-31537: Update readline documentation example. (GH-3925) (GH-3948) https://github.com/python/cpython/commit/10eb14e2c5fe08c4193668530eaef156e07... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
Mariatta Wijaya <mariatta.wijaya@gmail.com> added the comment: Fixed. Thanks! ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: -Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue31537> _______________________________________
participants (4)
-
bazwal
-
Bradley Smith
-
Mariatta Wijaya
-
Roundup Robot