From 3b0eb017b6a09261f02a4ff6d4f9483ac18e6b29 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 15 Dec 2017 07:35:58 -0500 Subject: [PATCH] Bang on Python 3.6 MAKE_FUNCTION --- test/bytecode_3.6/01_named_and_kwargs.pyc | Bin 0 -> 700 bytes uncompyle6/semantics/make_function.py | 45 +++++++++++++++------- uncompyle6/semantics/pysource.py | 13 ++++++- 3 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 test/bytecode_3.6/01_named_and_kwargs.pyc diff --git a/test/bytecode_3.6/01_named_and_kwargs.pyc b/test/bytecode_3.6/01_named_and_kwargs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4fa92e31e661d74d3a2a13206248dd90d82f5c46 GIT binary patch literal 700 zcmZWlO>fgc5Z$pI$4TlWZH3^@$s8z<8(#vI^Z+QArV{dH<$BiD3V&(Wp+w5DXRciO z2lz|Aa;o?TIWgn3fW%tw&3bod-preY;qXKF>(k5=;-~m$4QT&{VBZs=Py!)yaUTy* zppU)+s&Xo#!^O!KUTxv| z79MWl#WL!*LsYpgbfb)Ir)gCbs%&I!RHnZw+uqk@u1h8VyYOveblSA{R8co;$&akm zrTmiQE6SUo%92&yNUPFDS7jUOk|gRXPxv>bfkmG%A^_o-VEM3X6Ba*2G-^Go@+=N+ zOWAmUq$rzpt>ST#=hdYwtDT_fQL6EoxT*=5*hDjAVimJ@N83kM7j>?rtyU&gN9U`H z*|Vc3Pi2`D3T0BF{Ct_13;VcUw}GUobR*@M(yc=zd@~_VUEb5;$mm93xsBMs#>rgr z8y1~x= 3.4 and not (n.kind in ('kwargs', 'kwargs1', 'kwarg')): - continue - else: - self.preorder(n) - break - else: + # FIXME: this is not correct for 3.5. or 3.6 (which works different) + # and 3.7? + if 3.0 <= self.version <= 3.2: kwargs = node[0] last = len(kwargs)-1 i = 0 @@ -605,10 +597,37 @@ def make_function3(self, node, is_lambda, nested=1, codeNode=None): self.preorder(n[1]) if i < last: self.write(', ') + pass i += 1 pass pass pass + elif self.version <= 3.5: + # FIXME this is not qute right for 3.5 + for n in node: + if n == 'pos_arg': + continue + elif self.version >= 3.4 and not (n.kind in ('kwargs', 'kwargs1', 'kwarg')): + continue + else: + self.preorder(n) + break + elif self.version >= 3.6: + d = node[1] + if d == 'expr': + d = d[0] + assert d == 'dict' + defaults = [self.traverse(n, indent='') for n in d[:-2]] + names = eval(self.traverse(d[-2])) + assert len(defaults) == len(names) + sep = '' + # FIXME: possibly handle line breaks + for i, n in enumerate(names): + self.write(sep) + self.write("%s=%s" % (n, defaults[i])) + sep = ', ' + pass + pass pass if code_has_star_star_arg(code): diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 63af9414..99fdd188 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -568,8 +568,17 @@ class SourceWalker(GenericASTTraversal, object): self.n_build_tuple_unpack_with_call = build_unpack_tuple_with_call def build_unpack_map_with_call(node): - sep = '**' - for n in node[:-1]: + n = node[0] + if n == 'expr': + n = n[0] + if n == 'dict': + self.call36_dict(n) + first = 1 + sep = ', **' + else: + first = 0 + sep = '**' + for n in node[first:-1]: self.f.write(sep) self.preorder(n) sep = ', **'