Skip to content

Add --pager to %whos and %history 🤖🤖 - #15408

Open
wolfgang-aura wants to merge 1 commit into
ipython:mainfrom
wolfgang-aura:mailman/issue-9891
Open

wolfgang-aura wants to merge 1 commit into
ipython:mainfrom
wolfgang-aura:mailman/issue-9891

Conversation

@wolfgang-aura

Copy link
Copy Markdown

Closes #9891. 🤖🤖

%whos and %history print straight to the console, so checking the namespace or recent input leaves a long listing in the scrollback. This adds a --pager flag to both, following @takluyver's suggestions on the issue: a new option on each existing magic, routed through IPython.core.page.page() instead of a pager subprocess.

  • %history --pager writes into a StringIO instead of sys.stdout and passes the text to page.page(). Combining it with -f FILENAME raises a UsageError, since the output cannot go to both.
  • %whos --pager strips the flag, runs the usual listing under redirect_stdout, and pages the captured text. The other %whos arguments (type filters) still apply.
  • page.page() keeps its usual behaviour: short output is printed as normal, and it handles $PAGER and Windows.

A whatsnew entry is in docs/source/whatsnew/pr/magics-pager-option.rst, and the %whos docstring mentions the flag. Size: 5 files, 68 lines added, 2 removed.

Tests

test_history_magic_pager in tests/test_history.py and test_whos_pager in tests/test_magic.py patch page.page, check that the output reaches it rather than stdout, and check the --pager -f refusal. 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 --pager to 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: redirect magic's result to pager

1 participant