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

Tuple unpacking for shell escape #5305

Closed
wimglenn opened this issue Mar 9, 2014 · 5 comments · Fixed by #5321
Closed

Tuple unpacking for shell escape #5305

wimglenn opened this issue Mar 9, 2014 · 5 comments · Fixed by #5321
Assignees
Milestone

Comments

@wimglenn
Copy link
Contributor

wimglenn commented Mar 9, 2014

Assigning the output of a !shell_escape command to a variable results in a list of strings. Even when the output is a single line, the result will be a list with one element. Tuple unpacking on this list is inconsistent with the tuple unpacking syntax in python, only a subset of cases are working. In the examples below, the first case works correctly but the 2nd case (one-element unpack) and the 3rd (splat unpacking) are syntax errors.

In [1]: a, b, c = !echo 'a\nb\nc'

In [2]: a, = !echo 'a'
  File "<ipython-input-2-cf81f7d7733e>", line 1
    a, = !echo 'a'
         ^
SyntaxError: invalid syntax


In [3]: a, *bc = !echo 'a\nb\nc'
  File "<ipython-input-3-471e46e39f1a>", line 1
    a, *bc = !echo 'a\nb\nc'
             ^
SyntaxError: invalid syntax

My system info:

wim@wim-zenbook:~$ python3 -c "import IPython; print(IPython.sys_info())"
{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/lib/python3/dist-packages/IPython',
 'ipython_version': '0.13.2',
 'os_name': 'posix',
 'platform': 'Linux-3.11.0-18-generic-x86_64-with-Ubuntu-13.10-saucy',
 'sys_executable': '/usr/bin/python3',
 'sys_platform': 'linux',
 'sys_version': '3.3.2+ (default, Feb 28 2014, 00:52:16) \n[GCC 4.8.1]'}
@takluyver
Copy link
Member

PR #5321 addresses this.

@wimglenn
Copy link
Contributor Author

That was quick!

@takluyver
Copy link
Member

The actual fix was easy enough, since I'm already familiar with that code - just a regex that was a bit too restrictive.

@wimglenn
Copy link
Contributor Author

There are also cases I didn't mention like first, *blah, last, will the regex also handle them?

@takluyver
Copy link
Member

It should do. That PR has been merged now, so feel free to pull from master and try it out.

@minrk minrk added this to the 2.0 milestone Mar 26, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
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 a pull request may close this issue.

3 participants