Repository navigation
Use %% in the @magic_arguments usage line of cell magics 🤖🤖 - #15432
Open
ShivamSharma43 wants to merge 1 commit into
Open
ShivamSharma43 wants to merge 1 commit into
ShivamSharma43 wants to merge 1 commit into
Conversation
The usage line generated by @magic_arguments always started with %, so the help of cell magics such as %%capture, %%writefile and %%html showed "%capture ...". The @cell_magic/@register_cell_magic markers now record the magic kind on the function, and construct_parser uses a formatter with the %% prefix for cell magics. Line and line/cell magics keep %. Fixes ipython#14715 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Carreau
force-pushed
the
fix/14715-cell-magic-usage-prefix
branch
from
October 21, 2026 09:40
8ecb434 to
efa5e86
Compare
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.
🤖🤖 Fixes #14715.
The usage line built by
@magic_arguments()always started with%, becauseMagicHelpFormatter.add_usagehard-codes that prefix. So the help of cell magics showed the line-magic form:The same happens for
%%writefile,%%htmland%%script.The parser is built when
@magic_arguments()runs, and at that point it has no way to know the magic kind. In the documented decorator order,@cell_magic/@register_cell_magicsit under@magic_arguments()and run first. So:_method_magic_markerand_function_magic_markerdecorators now record the kind on the function, as_ipython_magic_kind(MAGIC_KIND_ATTR, next to the existing_ipython_magic_*attributes).construct_parseruses a newCellMagicHelpFormatter, which uses the%%prefix, when the kind is"cell". Aformatter_classpassed through@kwdsstill wins.%, so%time,%timeitand%code_wrapdon't change.After the change:
If
@cell_magicis applied above@magic_arguments(), the parser has already been built and the help keeps%. No built-in magic uses that order.Separately,
%%script?shows%%shebangbecause@cell_magic("script")names the magic differently from the method, andreal_name()uses the function name. I left that out to keep this PR to the prefix.The new test in
tests/test_magic_arguments.pycovers a line magic, a cell magic (both the bare and the named@cell_magic("...")form) and a line/cell magic.🤖 Generated with Claude Code