Correct bug in 3.5+ build_list with UNPACK

This commit is contained in:
rocky
2017-04-15 22:34:56 -04:00
parent 31c28d0220
commit 5477ca294d
2 changed files with 11 additions and 12 deletions

View File

@@ -3,3 +3,4 @@
{**{'a': 1, 'b': 2}}
{'x': 1, **{'y': 2}}
# {'c': 1, {'d': 2}, **{'e': 3}}
[*[]]

View File

@@ -1536,22 +1536,20 @@ class SourceWalker(GenericASTTraversal, object):
# will assume that if the text ends in *.
last_was_star = self.f.getvalue().endswith('*')
if lastnodetype.startswith('BUILD_LIST'):
self.write('['); endchar = ']'
elif lastnodetype.startswith('BUILD_TUPLE'):
self.write('('); endchar = ')'
elif lastnodetype.startswith('BUILD_SET'):
self.write('{'); endchar = '}'
elif lastnodetype.startswith('ROT_TWO'):
self.write('('); endchar = ')'
else:
raise 'Internal Error: n_build_list expects list or tuple'
have_star = False
if lastnodetype.endswith('UNPACK'):
# FIXME: need to handle range of BUILD_LIST_UNPACK
have_star = True
endchar = ''
else:
if lastnodetype.startswith('BUILD_LIST'):
self.write('['); endchar = ']'
elif lastnodetype.startswith('BUILD_TUPLE'):
self.write('('); endchar = ')'
elif lastnodetype.startswith('BUILD_SET'):
self.write('{'); endchar = '}'
elif lastnodetype.startswith('ROT_TWO'):
self.write('('); endchar = ')'
else:
raise 'Internal Error: n_build_list expects list or tuple'
flat_elems = []
for elem in node: