Correct bugs in Python 3.2 source generation

This commit is contained in:
rocky
2016-05-16 15:50:45 -04:00
parent 73d784510a
commit 09a01dc783
2 changed files with 34 additions and 9 deletions

View File

@@ -492,11 +492,17 @@ class FragmentsWalker(pysource.SourceWalker, object):
p = self.prec
self.prec = 27
if hasattr(node[code_index], 'attr'):
# Python 2.5+ (and earlier?) does this
code = node[code_index].attr
elif hasattr(node[1][1], 'attr'):
code = node[1][1].attr
else:
assert False
if len(node[1]) > 1 and hasattr(node[1][1], 'attr'):
# Python 3.3+ does this
code = node[1][1].attr
elif hasattr(node[1][0], 'attr'):
# Python 3.2 does this
code = node[1][0].attr
else:
assert False, "Can't find code for comprehension"
assert iscode(code)
code = Code(code, self.scanner, self.currentclass)
@@ -1020,6 +1026,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
# Python 3.0..3.4 style key/value list in mapexpr
kv_node = node[1]
l = list(kv_node)
if len(l) > 0 and l[0].type == 'kv3':
# Python 3.2 does this
kv_node = node[1][0]
l = list(kv_node)
i = 0
while i < len(l):
l[1].parent = kv_node