GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” Use %% in the @magic_arguments usage line of cell magics ๐Ÿค–๐Ÿค– by ShivamSharma43 ยท Pull Request #15432 ยท ipython/ipython

Conversation

@ShivamSharma43

@ShivamSharma43 ShivamSharma43 commented Oct 11, 2026

Copy link
Copy Markdown

๐Ÿค–๐Ÿค– Fixes #14715.

The usage line built by @magic_arguments() always started with %, because MagicHelpFormatter.add_usage hard-codes that prefix. So the help of cell magics showed the line-magic form:

In [1]: %%capture?
::

  %capture [--no-stderr] [--no-stdout] [--no-display] [output]

The same happens for %%writefile, %%html and %%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_magic sit under @magic_arguments() and run first. So:

  • The _method_magic_marker and _function_magic_marker decorators now record the kind on the function, as _ipython_magic_kind (MAGIC_KIND_ATTR, next to the existing _ipython_magic_* attributes).
  • construct_parser uses a new CellMagicHelpFormatter, which uses the %% prefix, when the kind is "cell". A formatter_class passed through @kwds still wins.
  • Line and line/cell magics keep %, so %time, %timeit and %code_wrap don't change.

After the change:

  %%capture [--no-stderr] [--no-stdout] [--no-display] [output]
  %%writefile [-a] filename
  %%html [--isolated]
  %time [--no-raise-error]

If @cell_magic is applied above @magic_arguments(), the parser has already been built and the help keeps %. No built-in magic uses that order.

Separately, %%script? shows %%shebang because @cell_magic("script") names the magic differently from the method, and real_name() uses the function name. I left that out to keep this PR to the prefix.

The new test in tests/test_magic_arguments.py covers a line magic, a cell magic (both the bare and the named @cell_magic("...") form) and a line/cell magic.

๐Ÿค– Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot AI balanced review requested due to automatic review settings October 11, 2026 15:41
Copilot AI reviewed Oct 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ShivamSharma43 @claude @Carreau
Use %% in the @magic_arguments usage line of cell magics ๐Ÿค–๐Ÿค–
efa5e86
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 <[email protected]>
@Carreau
Carreau force-pushed the fix/14715-cell-magic-usage-prefix branch from 8ecb434 to efa5e86 Compare October 21, 2026 09:40

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

@magic_arguments() always use % in help regardless of line/cell magic

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ShivamSharma43
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.
You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.