Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input parsing issue with %prun #1412

Closed
wesm opened this issue Feb 18, 2012 · 1 comment · Fixed by #1414
Closed

Input parsing issue with %prun #1412

wesm opened this issue Feb 18, 2012 · 1 comment · Fixed by #1414

Comments

@wesm
Copy link

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
Copy link
Member

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 as completed in 4480299 Feb 27, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
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 ipython#1412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants