This is an input transformation performed by the EscapedCommand
class, specifically here. It's not part of autocall (details see below) which is handled by prefilter.AutoHandler
. I couldn't find any public documentation on "escaped commands" and the class' docstring just mentions that it is a "transformer for escaped commands like %foo
, !foo
, or /foo
". So I get the impression that the transformation for input like , a b
is an (unintended) side effect of some other feature, as it's not publicly documented and doesn't seem to be of any use.
We can request the current IPython shell by importing the corresponding module and then check what component modifies the input:
In [1]: import IPython
In [2]: shell = IPython.get_ipython()
In [3]: %autocall
Automatic calling is: Smart
In [4]: shell.prefilter(',f a b') # autocall (note the function name 'f'), not applied since there is no callable `f` in the global namespace
Out[4]: ',f a b'
In [5]: f = lambda x,y: x+y
In [6]: shell.prefilter(',f a b') # autocall (note the function name 'f'), now it works
------> f("a", "b")
Out[6]: 'f("a", "b")'
In [7]: shell.prefilter(', a b') # not identified as autocall --> remains unchanged
Out[7]: ', a b'
In [8]: shell.transform_cell(', a b') # however, it gets transformed by `EscapedCommand`
Out[8]: '("a", "b")\n'
For autocall to work, we first have to activate it via the "magic" command %autocall
. Also the indicated function name (f
) must be present in the namespace and be callable. %quickref
provides a brief overview of the autocall feature (scroll down to "Autocall"):
Autocall:
f 1,2 : f(1,2) # Off by default, enable with %autocall magic.
/f 1,2 : f(1,2) (forced autoparen)
,f 1 2 : f("1","2")
;f 1 2 : f("1 2")