You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
2.6.9 list comprehension
This commit is contained in:
BIN
test/bytecode_2.6/05_for_for.pyc
Normal file
BIN
test/bytecode_2.6/05_for_for.pyc
Normal file
Binary file not shown.
2
test/simple_source/comprehension/05_for_for.py
Normal file
2
test/simple_source/comprehension/05_for_for.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# Python 2.6 uses SETUP_LOOP while 2.7 doesn't
|
||||
(e for s in (self, other) for e in s)
|
@@ -134,6 +134,9 @@ class Python26Parser(Python2Parser):
|
||||
lc_body ::= LOAD_NAME expr LIST_APPEND
|
||||
lc_body ::= LOAD_FAST expr LIST_APPEND
|
||||
|
||||
comp_for ::= SETUP_LOOP expr _for designator comp_iter JUMP_BACK POP_BLOCK COME_FROM
|
||||
|
||||
|
||||
# Make sure we keep indices the same as 2.7
|
||||
setup_loop_lf ::= SETUP_LOOP LOAD_FAST
|
||||
genexpr_func ::= setup_loop_lf FOR_ITER designator comp_iter JUMP_BACK POP_BLOCK COME_FROM
|
||||
|
@@ -1078,15 +1078,17 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
ast = ast[0][0][0]
|
||||
|
||||
n = ast[iter_index]
|
||||
assert n == 'comp_iter'
|
||||
assert n == 'comp_iter', n
|
||||
|
||||
# find innermost node
|
||||
while n == 'comp_iter': # list_iter
|
||||
n = n[0] # recurse one step
|
||||
if n == 'comp_for': n = n[3]
|
||||
if n == 'comp_for':
|
||||
n = n[4] if n[0] == 'SETUP_LOOP' else n[3]
|
||||
elif n == 'comp_if': n = n[2]
|
||||
elif n == 'comp_ifnot': n = n[2]
|
||||
assert n == 'comp_body', ast
|
||||
|
||||
assert n == 'comp_body', n
|
||||
|
||||
self.preorder(n[0])
|
||||
self.write(' for ')
|
||||
@@ -1124,7 +1126,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prec = 27
|
||||
code = node[code_index].attr
|
||||
|
||||
assert iscode(code)
|
||||
assert iscode(code), node[code_index]
|
||||
code = Code(code, self.scanner, self.currentclass)
|
||||
|
||||
ast = self.build_ast(code._tokens, code._customize)
|
||||
@@ -1144,7 +1146,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
else:
|
||||
ast = ast[0][0]
|
||||
n = ast[iter_index]
|
||||
assert n == 'list_iter'
|
||||
assert n == 'list_iter', n
|
||||
|
||||
## FIXME: I'm not totally sure this is right.
|
||||
|
||||
|
Reference in New Issue
Block a user