Skip to content
Advertisement

Inputting just a comma returns strange behaviour

Today I by mistake inputted just a comma on an interactive session
Input:

JavaScript

and I noticed strangely that it did not return an error but instead:
Output

JavaScript

So I explored a bit this behaviour and tried some random stuff, and it seems like it creates tuples of strings, but it seems like these objects cannot be interacted with:

JavaScript

returns:

JavaScript

Trying to assign those tuples or making some == checks doesn’t really work but return errors.
I couldn’t find any answer or documentation about this behaviour. Anyone know what’s happening here?

EDIT: I am using Python 3.9.8 and running in VSCode interactive window with IPython. As someone pointed out in the comments this is not the behaviour when running from the terminal

Advertisement

Answer

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:

JavaScript

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”):

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement