From 1fe432585e8d9f8f2a5d7ccb04159752414a8134 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 28 Feb 2018 16:22:33 -0500 Subject: [PATCH] Keep pre-3.6 listcomp code patterns in 3.6 --- test/bytecode_3.6/06_listcomp_nest.pyc | Bin 660 -> 856 bytes test/simple_source/bug36/06_listcomp_nest.py | 6 ++++++ uncompyle6/parsers/parse3.py | 16 +++++++++------- uncompyle6/semantics/pysource.py | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/test/bytecode_3.6/06_listcomp_nest.pyc b/test/bytecode_3.6/06_listcomp_nest.pyc index de374761614c5ccb7a38d7024676352507e87ab7..7873bf1e9d706882fd21085c5a125b7c5b77b1bb 100644 GIT binary patch delta 284 zcmbQjdV?**n3tDprOfmwHf9Ef#|%gS$Y*c>;$j^jkp_XxDGVu$EsRkNDNHHMIgC+^ zDJ&_hEexrQSxhbr&5TjZDa^qPnrs_wG@0sO0<|&tB{PC3AYcMwRv>l;;$kr%kO#>NG9K{La U7f;S*Qs!azR WG?_U3G#QHofJ!E7Gb^(IX$Am%&= 2 and tokens[i-2] == 'LOAD_LISTCOMP'): - if self.version < 3.6: - rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr " - "GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname)) - else: - # 3.6+ bundles all of the 'exprs' in the rule above into a tuple. - rule_pat = ("listcomp ::= load_closure LOAD_LISTCOMP %%s%s expr " - "GET_ITER CALL_FUNCTION_1" % (opname,)) + if self.version >= 3.6: + # 3.6+ sometimes bundles all of the + # 'exprs' in the rule above into a + # tuple. + rule_pat = ("listcomp ::= load_closure LOAD_LISTCOMP %%s%s " + "expr GET_ITER CALL_FUNCTION_1" % (opname,)) + self.add_make_function_rule(rule_pat, opname, token.attr, customize) + rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr " + "GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname)) self.add_make_function_rule(rule_pat, opname, token.attr, customize) if is_pypy or (i >= 2 and tokens[i-2] == 'LOAD_LAMBDA'): diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 7cb908b8..b90760a5 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1697,6 +1697,7 @@ class SourceWalker(GenericASTTraversal, object): assert n == 'lc_body', ast + # FIXME: add indentation around "for"'s and "in"'s self.preorder(n[0]) if self.version < 3.6: self.write(' for ')