You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Fix some Python set comprehension bugs
This commit is contained in:
@@ -9,5 +9,5 @@ for path in sys.argv[1:]:
|
|||||||
cfile = "bytecode_%s/%s" % (version, short) + 'c'
|
cfile = "bytecode_%s/%s" % (version, short) + 'c'
|
||||||
print("byte-compiling %s to %s" % (path, cfile))
|
print("byte-compiling %s to %s" % (path, cfile))
|
||||||
py_compile.compile(path, cfile)
|
py_compile.compile(path, cfile)
|
||||||
if sys.version >= (2, 6, 0):
|
if isinstance(version, str) or version >= (2, 6, 0):
|
||||||
os.system("../bin/uncompyle6 -a -t %s" % cfile)
|
os.system("../bin/uncompyle6 -a -t %s" % cfile)
|
||||||
|
Binary file not shown.
BIN
test/bytecode_3.4/05_3x_set_comphension.pyc
Normal file
BIN
test/bytecode_3.4/05_3x_set_comphension.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,5 @@ def __new__(classdict):
|
|||||||
members = {k: classdict[k] for k in classdict._member_names}
|
members = {k: classdict[k] for k in classdict._member_names}
|
||||||
return members
|
return members
|
||||||
|
|
||||||
# Bug from Python 3.4 asyncio/tasks.py
|
# Bug from 3.5.1 enum.py in 2.7, and 3.x
|
||||||
def as_completed(fs, *, loop=None):
|
{a for b in bases for a in b.__dict__}
|
||||||
todo = {async(f, loop=loop) for f in set(fs)}
|
|
||||||
|
@@ -1155,13 +1155,19 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
# find innermost node
|
# find innermost node
|
||||||
if_node = None
|
if_node = None
|
||||||
|
comp_for = None
|
||||||
|
comp_designator = None
|
||||||
|
if n == 'comp_iter':
|
||||||
|
comp_for = n
|
||||||
|
comp_designator = ast[3]
|
||||||
|
|
||||||
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 in ('list_for', 'comp_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', 'comp_if']:
|
elif n in ('list_if', 'list_if_not', 'comp_if'):
|
||||||
if_node = n[0]
|
if_node = n[0]
|
||||||
if n[1] == 'designator':
|
if n[1] == 'designator':
|
||||||
designator = n[1]
|
designator = n[1]
|
||||||
@@ -1169,16 +1175,23 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Python 2.7+ starts including set_comp_body
|
||||||
# Python 3.5+ starts including setcomp_func
|
# Python 3.5+ starts including setcomp_func
|
||||||
assert n.type in ('lc_body', 'comp_body', 'setcomp_func'), ast
|
assert n.type in ('lc_body', 'comp_body', 'setcomp_func', 'set_comp_body'), ast
|
||||||
assert designator, "Couldn't find designator in list/set comprehension"
|
assert designator, "Couldn't find designator in list/set comprehension"
|
||||||
|
|
||||||
self.preorder(n[0])
|
self.preorder(n[0])
|
||||||
self.write(' for ')
|
self.write(' for ')
|
||||||
self.preorder(designator)
|
if comp_designator:
|
||||||
|
self.preorder(comp_designator)
|
||||||
|
else:
|
||||||
|
self.preorder(designator)
|
||||||
|
|
||||||
self.write(' in ')
|
self.write(' in ')
|
||||||
self.preorder(node[-3])
|
self.preorder(node[-3])
|
||||||
if if_node:
|
if comp_designator:
|
||||||
|
self.preorder(comp_for)
|
||||||
|
elif if_node:
|
||||||
self.write(' if ')
|
self.write(' if ')
|
||||||
self.preorder(if_node)
|
self.preorder(if_node)
|
||||||
self.prec = p
|
self.prec = p
|
||||||
|
Reference in New Issue
Block a user