From c9f364df9f78886e6bd73b0ad1ee4b8819ad56a6 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 31 Aug 2016 06:17:06 -0400 Subject: [PATCH] Python 3.x bug in handling var number of args --- test/bytecode_3.5/02_fn_varargs.pyc | Bin 0 -> 245 bytes test/simple_source/bug35/02_fn_varargs.py | 5 +++++ uncompyle6/semantics/pysource.py | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/bytecode_3.5/02_fn_varargs.pyc create mode 100644 test/simple_source/bug35/02_fn_varargs.py diff --git a/test/bytecode_3.5/02_fn_varargs.pyc b/test/bytecode_3.5/02_fn_varargs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a65c87ee3703563959b5b540a5e6267a61a67e5 GIT binary patch literal 245 zcmWgR<>mUe?pXLD1_p-5Knw>gK$Zg#7mERj6d+<`NMT|~VPY&XMKEdr literal 0 HcmV?d00001 diff --git a/test/simple_source/bug35/02_fn_varargs.py b/test/simple_source/bug35/02_fn_varargs.py new file mode 100644 index 00000000..42d568bf --- /dev/null +++ b/test/simple_source/bug35/02_fn_varargs.py @@ -0,0 +1,5 @@ +# From python 3.4 pstats.py +# Bug was not adding *, since *args covers that. And getting stream=None +# without * +def __init__(self, *args, stream=None): + pass diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index a1baeaa1..def3a00e 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -2010,8 +2010,12 @@ class SourceWalker(GenericASTTraversal, object): params.reverse() # back to correct order if 4 & code.co_flags: # flag 2 -> variable number of args - params.append('*%s' % code.co_varnames[argc]) + if self.version > 3.0: + params.append('*%s' % code.co_varnames[argc + args_node.attr[1]]) + else: + params.append('*%s' % code.co_varnames[argc]) argc += 1 + if 8 & code.co_flags: # flag 3 -> keyword args params.append('**%s' % code.co_varnames[argc]) argc += 1 @@ -2025,10 +2029,15 @@ class SourceWalker(GenericASTTraversal, object): # self.println(indent, '#flags:\t', int(code.co_flags)) if kw_args > 0: - if argc > 0: - self.write(", *, ") + if not (4 & code.co_flags): + if argc > 0: + self.write(", *, ") + else: + self.write("*, ") + pass else: - self.write("*, ") + self.write(", ") + for n in node: if n == 'pos_arg': continue