You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +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:
|
except pysource.SourceWalkerError as e:
|
||||||
# deparsing failed
|
# deparsing failed
|
||||||
print("\n")
|
print("\n")
|
||||||
|
print(co.co_filename)
|
||||||
if real_out != out:
|
if real_out != out:
|
||||||
print("\n", file=real_out)
|
print("\n", file=real_out)
|
||||||
print(e, file=real_out)
|
print(e, file=real_out)
|
||||||
|
@@ -39,8 +39,15 @@ class PythonParser(GenericASTBuilder):
|
|||||||
for i in dir(self):
|
for i in dir(self):
|
||||||
setattr(self, i, None)
|
setattr(self, i, None)
|
||||||
|
|
||||||
def error(self, token):
|
def error(self, tokens, index):
|
||||||
raise ParserError(token, token.offset)
|
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):
|
def typestring(self, token):
|
||||||
return token.type
|
return token.type
|
||||||
|
@@ -1095,20 +1095,21 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
## FIXME: I'm not totally sure this is right.
|
## FIXME: I'm not totally sure this is right.
|
||||||
|
|
||||||
# find innermost node
|
# find innermost node
|
||||||
list_if_node = None
|
if_node = None
|
||||||
while n in ('list_iter', 'comp_iter'):
|
while n in ('list_iter', 'comp_iter'):
|
||||||
n = n[0] # recurse one step
|
n = n[0] # recurse one step
|
||||||
if n == 'list_for':
|
if n == 'list_for':
|
||||||
if n[2] == 'designator':
|
if n[2] == 'designator':
|
||||||
designator = n[2]
|
designator = n[2]
|
||||||
n = n[3]
|
n = n[3]
|
||||||
elif n in ['list_if', 'list_if_not']:
|
elif n in ['list_if', 'list_if_not', 'comp_if']:
|
||||||
list_if_node = n[0]
|
if_node = n[0]
|
||||||
if n[1] == 'designator':
|
if n[1] == 'designator':
|
||||||
designator = n[1]
|
designator = n[1]
|
||||||
n = n[2]
|
n = n[2]
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert n.type in ('lc_body', 'comp_body'), ast
|
assert n.type in ('lc_body', 'comp_body'), ast
|
||||||
assert designator, "Couldn't find designator in list/set comprehension"
|
assert designator, "Couldn't find designator in list/set comprehension"
|
||||||
|
|
||||||
@@ -1117,9 +1118,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.preorder(designator)
|
self.preorder(designator)
|
||||||
self.write(' in ')
|
self.write(' in ')
|
||||||
self.preorder(node[-3])
|
self.preorder(node[-3])
|
||||||
if list_if_node:
|
if if_node:
|
||||||
self.write(' if ')
|
self.write(' if ')
|
||||||
self.preorder(list_if_node)
|
self.preorder(if_node)
|
||||||
self.prec = p
|
self.prec = p
|
||||||
|
|
||||||
def listcomprehension_walk2(self, node):
|
def listcomprehension_walk2(self, node):
|
||||||
|
Reference in New Issue
Block a user