[Updated to reflect that this is only true of single, not double quotes.]
Apparent bug in %run (or perhaps more generally in magic). The following fails:
%run 'a \' b.py'
More specifically, it fails with a "ValueError: no closing quotation" from shlex: https://gist.github.com/1446761
Changed the title to be more accurate. For the reason described by @minrk at #1109 (posix asymmetry between single and double quotes), this only fails when the filename is single-quoted, not double.
Therefore a workaround is to always use double quotes if the filename contains single quotes, whether or not it also contains double quotes (which can be escaped without failure).
For the record, PR #1130 removes the shlex ValueError but does not solve the issue (run magic truncates filename at first escaped single quote)
Right, and it may even be wrong to prevent the ValueError, because escaping quotes in a single-quoted string is invalid (as long as we are using shlex).
I don't think there is anything to do here. python 'a \' b.py' won't work on the command line either.
python 'a \' b.py'
Solution is to use double quotes, or the ugly but functional 'a '"'"' b.py'.
'a '"'"' b.py'
It seems to come down to what mental model we ask users to adopt. At first glance, it would seem more user-friendly to be able to interpret any valid python string here, but perhaps we should just be clear that this is a posix filename string, not a python string, and make sure that the documentation and help are very clear about that. (Though how we get "very clear" about the mush between posix and windows filenames is another issue.)
While I agree that the posix/window situation is a bit messy, indeed the interpretation of text in the line of magic calls, and especially the one for %run, leans far closer to the semantics of a posix command-line than that of a python string.
So if anything, I suggest that the way to close this bug would just be an improvement to the %run docstring emphasizing this point, perhaps along with a note in the main magics docs (could just be in %magic itself) indicating that in general, users shouldn't expect python semantics in magic calls, since each magic ultimately decides what semantics to impose on an argument it receives as a pure string.