3.4 set comprehension if bug

This commit is contained in:
rocky
2016-06-18 23:43:50 -04:00
parent 724faf9a3a
commit 73df5f3737
4 changed files with 23 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
# Bug in python 3.4 abc.py
# Set comprehension
abstracts = {name
for name, value in namespace.items()
if getattr(value, "__isabstractmethod__", False)}

View File

@@ -34,6 +34,7 @@ def uncompyle(version, co, out=None, showasm=False, showast=False,
except pysource.SourceWalkerError as e:
# deparsing failed
print("\n")
print(co.co_filename)
if real_out != out:
print("\n", file=real_out)
print(e, file=real_out)

View File

@@ -39,8 +39,15 @@ class PythonParser(GenericASTBuilder):
for i in dir(self):
setattr(self, i, None)
def error(self, token):
raise ParserError(token, token.offset)
def error(self, tokens, index):
start = index - 2 if index - 2 > 0 else 0
finish = index +2 if index + 2 < len(tokens) else len(tokens)
err_token = tokens[index]
print("Token context:")
for i in range(start, finish):
indent = ' ' if i != index else '-> '
print("%s%s" % (indent, tokens[i]))
raise ParserError(err_token, err_token.offset)
def typestring(self, token):
return token.type

View File

@@ -1095,20 +1095,21 @@ class SourceWalker(GenericASTTraversal, object):
## FIXME: I'm not totally sure this is right.
# find innermost node
list_if_node = None
if_node = None
while n in ('list_iter', 'comp_iter'):
n = n[0] # recurse one step
if n == 'list_for':
if n[2] == 'designator':
designator = n[2]
n = n[3]
elif n in ['list_if', 'list_if_not']:
list_if_node = n[0]
elif n in ['list_if', 'list_if_not', 'comp_if']:
if_node = n[0]
if n[1] == 'designator':
designator = n[1]
n = n[2]
pass
pass
assert n.type in ('lc_body', 'comp_body'), ast
assert designator, "Couldn't find designator in list/set comprehension"
@@ -1117,9 +1118,9 @@ class SourceWalker(GenericASTTraversal, object):
self.preorder(designator)
self.write(' in ')
self.preorder(node[-3])
if list_if_node:
if if_node:
self.write(' if ')
self.preorder(list_if_node)
self.preorder(if_node)
self.prec = p
def listcomprehension_walk2(self, node):