Add --pager to %whos and %history 🤖🤖 - #15408
Open
wolfgang-aura wants to merge 1 commit into
Open
wolfgang-aura wants to merge 1 commit into
wolfgang-aura wants to merge 1 commit into
Conversation
Closes ipython#9891. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9891. 🤖🤖
%whosand%historyprint straight to the console, so checking the namespace or recent input leaves a long listing in the scrollback. This adds a--pagerflag to both, following @takluyver's suggestions on the issue: a new option on each existing magic, routed throughIPython.core.page.page()instead of a pager subprocess.%history --pagerwrites into aStringIOinstead ofsys.stdoutand passes the text topage.page(). Combining it with-f FILENAMEraises aUsageError, since the output cannot go to both.%whos --pagerstrips the flag, runs the usual listing underredirect_stdout, and pages the captured text. The other%whosarguments (type filters) still apply.page.page()keeps its usual behaviour: short output is printed as normal, and it handles$PAGERand Windows.A whatsnew entry is in
docs/source/whatsnew/pr/magics-pager-option.rst, and the%whosdocstring mentions the flag. Size: 5 files, 68 lines added, 2 removed.Tests
test_history_magic_pagerintests/test_history.pyandtest_whos_pagerintests/test_magic.pypatchpage.page, check that the output reaches it rather than stdout, and check the--pager -frefusal. Both use the new flag, so neither can pass without this change. The patch was written and checked on Windows 11 with Python 3.14.3 only; this PR's CI is the check on other platforms.Alternatives not taken
A generic decorator that adds
--pagerto every magic. takluyver advised doing it only in the magics where it makes sense, and a decorator would have to reach into each magic's argument parsing.AI disclosure
This change was written with AI assistance: Claude (
claude-opus-5-5) wrote the patch and a second Claude (claude-opus-5-5) instance reviewed it, running under the Mailman harness. 🤖🤖🤖 Generated with Claude Code