Skip to content

Commit

Permalink
Improve assignment regex to match more tuple unpacking syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Mar 10, 2014
1 parent 0132445 commit 81b7d34
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions IPython/core/inputtransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,17 @@ def strip_encoding_cookie():
while line is not None:
line = (yield line)


assign_system_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))'
r'\s*=\s*!\s*(?P<cmd>.*)')
_assign_pat = \
r'''(?P<lhs>(\s*)
([\w\.]+) # Initial identifier
(\s*,\s*
\*?[\w\.]+)* # Further identifiers for unpacking
\s*?,? # Trailing comma
)
\s*=\s*
'''

assign_system_re = re.compile(r'{}!\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE)
assign_system_template = '%s = get_ipython().getoutput(%r)'
@StatelessInputTransformer.wrap
def assign_from_system(line):
Expand All @@ -529,8 +537,7 @@ def assign_from_system(line):

return assign_system_template % m.group('lhs', 'cmd')

assign_magic_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))'
r'\s*=\s*%\s*(?P<cmd>.*)')
assign_magic_re = re.compile(r'{}%\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE)
assign_magic_template = '%s = get_ipython().magic(%r)'
@StatelessInputTransformer.wrap
def assign_from_magic(line):
Expand Down

0 comments on commit 81b7d34

Please sign in to comment.