Better cell magic by removing some of the syntax limitations #15643
Closed
soerenwolfers
started this conversation in
Ideas
Replies: 1 comment
-
This appears like a suggestion for https://github.com/ipython/ipython or https://github.com/ipython/ipykernel. JupyterLab itself is kernel-agnostic. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Below, I'm making suggestions (A)-(E) how I think cell magic could be made even better.
I'd be interested if anyone sees any backwards compatibility issues that may arise.
As far as I can tell, each of my suggestions
(1) extends the set of legal cell contents
and all but (B) and (E)
(2) gives the same results on the previous set of legal cell contents
where the only reason that (B) and (E) do not give the same results on previous contents is that nested magic would trip (which I actually use quite frequently)
If I required triple-
%
for the new functionality, I think all my suggestions would satisfy both (1) and (2).If people generally think these are good ideas, I'd try and make a PR.
(A) Just about any cell magic I've ever used would have been better if it was possible to assign output via
similar to how it's already possible to do
More generally, I think it should simply be allowed to start
%%
-magic anywhere in a cell.Most cell magic I know instead implement awkward workarounds like
but since every cell magic uses its own syntax and most don't support things like assigning to dictionaries, this is a major hassle.
(B) Extending on the previous item, it'd be great if we could also have code after
%%
-magic, e.g.,(C) Just about any cell magic I've ever used would have been better if it was possible to do
and have this be translated to a regular function-call of the function registered as part of the cell-magic registration, the result of which would then do the actual cell-magic.
Most cell magic I know instead implements awkward workarounds like
sql -f -conn conn
but since every cell magic uses its own syntax and most don't support things like indexing dictionaries, this is a major hassle.For example, the
sql
magic above could be implemented by registeringwith Jupyter; and a simple
%%sql
without arguments could simply be translated to a call ofsql_cell_magic_wrapper
without arguments, i.e.,sql_cell_magic_wrapper()(<cell>)
(D) Cell magic should be allowed to fall back to line magic:
It's annoying to always have to remove/add
%
just because you're changing your mind whether you need an entire cell or not.(E) Further to (D), it should be legal to terminate a single-line
%%
-magic and continue the line non-magically, e.g.(A-E): In combination, it would be possible to do
or, if one so prefers,
Beta Was this translation helpful? Give feedback.
All reactions