You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
3.4 set comprehension if bug
This commit is contained in:
@@ -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)}
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user