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

ignore errors in shell.var_expand #1414

Merged
merged 1 commit into from Feb 27, 2012
Merged

ignore errors in shell.var_expand #1414

merged 1 commit into from Feb 27, 2012

Conversation

minrk
Copy link
Member

@minrk minrk commented Feb 18, 2012

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).

A few tests included.

The real answer to this problem is to not call var_expand where it shouldn't be called, just as with the argument split. We really treat all magics as shell options, and we shouldn't, but until we get that whole logic cleaned up, this is a temporary solution. The only drawback is that ls $files will result in ls $files instead of NameError if files is undefined, which is the most logical behavior. But valid calls to %prun are more important than raising the right error in invalid calls to ls.

closes #1412

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).

Tests included.
@takluyver
Copy link
Member

Just to note: catching the exception there will mean that if any part can't be expanded, no part will be: if only a is defined, echo {a} {b} won't expand a or b. I think that's probably the behaviour we want, but it's worth mentioning.

I agree that we should in due course distinguish magics which take shell options from magics which take Python code.

Other than that, this seems fine to me.

@minrk
Copy link
Member Author

minrk commented Feb 19, 2012

Yes, good point. This is obviously not the optimal solution, but since the 'real' answer is that it should not be called in the first place, it seems like an acceptable band-aid until magic parsing is rewritten from scratch.

@minrk
Copy link
Member Author

minrk commented Feb 19, 2012

We should let this sit for a day or two, in case anyone thinks raising a NameError when you do !command {typo} is sufficiently important that we need a more careful fix right now.

minrk added a commit that referenced this pull request Feb 27, 2012
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
@minrk minrk merged commit 4480299 into ipython:master Feb 27, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input parsing issue with %prun
2 participants