From 9cb99e32905f9c812d0bb7c9c74832c218cbf794 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 15 Dec 2017 19:18:27 -0500 Subject: [PATCH] 3.6 FUNCTION_EX_KW fixes --- test/bytecode_3.6/07_closure_bug2.pyc | Bin 0 -> 666 bytes uncompyle6/parsers/parse36.py | 2 +- uncompyle6/semantics/pysource.py | 29 +++++++++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 test/bytecode_3.6/07_closure_bug2.pyc diff --git a/test/bytecode_3.6/07_closure_bug2.pyc b/test/bytecode_3.6/07_closure_bug2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f1baf9b36487e4e1b09414b0c0aa94ef78dbd6c GIT binary patch literal 666 zcmZ`$u}&N@5S{Vvh2wHak&=Kyk)%kGZH|Z(X%LD;q;w|*nrItqv3&^et}phkNYGK; zNl=mR;79lfx2gDrRLtz^5Q-E_9?y98y*JPMacymIy2$cd0q_SNt(5Z5w8L8p8Z=rc zF-L^2poLBrpc5nJNuKER0J7d4eFYiD-kC3^L2IbYPyD@O53X!9(5hD{1JT)`YK;SwhuOMi|RVkU?u89xX!d_emR!(LOk z!V{Ro?;#R=1~a_I1Na8}@SV&N6vs6DP8M_Je%wXh65+sG2%r^Bysc*}w%BRxFKO1P>f~@eJ%9CIxiLLFfvTc3 zQpSOlrPB>rlJpSrM^o6Y6b2hXF;uCjxVpQGs TA91h^-;KW0N$);ivJJ&O#VnLF literal 0 HcmV?d00001 diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index f07f277e..451ea196 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -150,7 +150,7 @@ class Python36Parser(Python35Parser): build_map_unpack_with_call CALL_FUNCTION_EX_KW call_ex_kw3 ::= expr - tuple + expr expr CALL_FUNCTION_EX_KW """, diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 3104a088..4f7dbeb6 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -588,6 +588,9 @@ class SourceWalker(GenericASTTraversal, object): self.n_build_map_unpack_with_call = build_unpack_map_with_call def call_ex_kw2(node): + """Handle CALL_FUNCTION_EX 2 (have KW) but with + BUILD_{MAP,TUPLE}_UNPACK_WITH_CALL""" + # This is weird shit. Thanks Python! self.preorder(node[0]) self.write('(') @@ -622,17 +625,27 @@ class SourceWalker(GenericASTTraversal, object): self.n_call_ex_kw2 = call_ex_kw2 def call_ex_kw3(node): + """Handle CALL_FUNCTION_EX 2 (have KW) but without + BUILD_{MAP,TUPLE}_UNPACK_WITH_CALL""" self.preorder(node[0]) self.write('(') - tup = node[1] - assert tup == 'tuple' - self.call36_tuple(tup) - expr = node[2] - if len(tup) > 0: - # if tup[0].attr > 0: + args = node[1][0] + if args == 'tuple': + if self.call36_tuple(args) > 0: + self.write(', ') + pass + pass + else: + self.write('*') + self.preorder(args) self.write(', ') + pass + + kwargs = node[2] + if kwargs == 'expr': + kwargs = kwargs[0] self.write('**') - self.preorder(expr) + self.preorder(kwargs) self.write(')') self.prune() self.n_call_ex_kw3 = call_ex_kw3 @@ -663,7 +676,7 @@ class SourceWalker(GenericASTTraversal, object): sep = ', ' self.indent_less(INDENT_PER_LEVEL) - return + return len(flat_elems) self.call36_tuple = call36_tuple def call36_dict(node):