ipython
ipython copied to clipboard
Help end syntax + line magic interaction
The help end syntax takes higher precedence than the line magic syntax; this is intentional:
# This needs to be higher priority (lower number) than EscapedCommand so
# that inspecting magics (%foo?) works.
However, if a line magic is handling text that may end in a ?
or ??
, this can lead to unexpected results -- %somemagic whatever?
leading to Object `whatever` not found.
instead of the line magic ever being called. (In my case I can tell users to just add a space after the ?
, but this isn't necessarily general.)
Proposed solution: if a line magic line ends in ?
/??
, only call the help transform if there is no whitespace intervening between the %
and the help end marker. As far as I can see this should handle the intended case for using %
and ?
together as well as let line magics work right in general, but maybe I'm missing something. (If it is this simple I can submit a PR, implementing it looks straightforward.)
Same issue here. Question mark could be part of the text handled by a custom-defined magic. Current token transform handling manipulates line magic input. Suggested solution: add support for line magic hints to disable token manipulation completely.
Workaround:
from IPython.core.inputtransformer2 import HelpEnd, EscapedCommand HelpEnd.priority = EscapedCommand.priority + 1