Skip to content

Recognise cell magics after leading comments 🤖🤖 - #15409

Open
00200200 wants to merge 1 commit into
ipython:mainfrom
00200200:fix-15312-cell-magic-leading-comments
Open

00200200 wants to merge 1 commit into
ipython:mainfrom
00200200:fix-15312-cell-magic-leading-comments

Conversation

@00200200

Copy link
Copy Markdown

Fixes #15312 🤖🤖

A comment (or blank line) above a cell magic is currently treated as the first line of the cell, so %%time is parsed as a line magic named %time and fails with Line magic function \%%time` not found`.

This adds a leading_comment_lines cleanup transform, next to the existing leading_empty_lines one. If the first real line of the cell starts with %%, leading comments and blanks are dropped so the cell magic is recognised. Ordinary Python cells and line magics are unchanged.

Tests

  • unit coverage for the new transform (comments + cell magic, comments + Python, comments + line magic, comment-only cells)
  • TransformerManager.transform_cell for the original reproducer
  • check_complete so a commented cell magic still waits for a blank line
  • InteractiveShell.run_cell integration with a registered cell magic

A narration comment above %%magic previously made the cell parse as a
line magic named %name. Drop those leading comments so the cell magic
runs, matching the existing leading-empty-line cleanup.

Fixes ipython#15312

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.

Comment lines above a cell magic make it parse as a line magic named %name, with a confusing error

1 participant