Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Input parsing issue with %prun #1412

wesm opened this Issue Feb 18, 2012 · 1 comment


None yet
2 participants

wesm commented Feb 18, 2012

In [5]: %prun grouped.agg({'value1' : 'mean', 'value2' : 'var', 'value3' : 'sum'})
  File "<string>", line 1
    'value1' : 'mean', 'value2' : 'var', 'value3' : 'sum'
SyntaxError: invalid syntax

minrk commented Feb 18, 2012

git bisect reveals f5687fc as the offender.

The issue is the new var_expand, which uses a DollarFormatter, rather than ItplNS. Formerly, $ was the only expansion, but since we now use string formatting, the {name} syntax is acceptable, and the magic is trying to format the string. This wasn't an issue, because variables wer unambiguous, as they were not Python syntax, but they are now.

The magic argument transform is proving itself to be in irredeemable mess, and needs to be reconsidered in a much cleaner way. For instance, this var_expand call should never be made on magics that aren't shell-ish.

Temporary workaround to just disable variable expansion, if you need it:

get_ipython().var_expand = lambda s, *args, **kwargs: s

@minrk minrk closed this in 4480299 Feb 27, 2012

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

@minrk minrk Merge pull request #1414 from minrk/var_expand
ignore errors in shell.var_expand

If an error is raised in the formatter, leave it untransformed. This means that var_expand("$foo") will return "$foo" if foo is undefined, but more importantly it will not raise when var_expand is used on literal code that doesn't expect to be expanded (e.g. %prun arguments).

closes #1412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment