You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Instruction fixup broken 3.x make_func...
for handling default values
This commit is contained in:
@@ -7,3 +7,9 @@ def foo3(bar, baz=1, qux=2):
|
||||
return 3
|
||||
def foo4(bar, baz, qux=1, quux=2):
|
||||
return 4
|
||||
|
||||
# From 3.6 compileall.
|
||||
# Bug was in omitting default which when used in an "if"
|
||||
# are treated as False would be
|
||||
def _walk_dir(dir, ddir=None, maxlevels=10, quiet=0):
|
||||
return
|
||||
|
@@ -459,26 +459,28 @@ def make_function3(self, node, is_lambda, nested=1, codeNode=None):
|
||||
|
||||
# MAKE_CLOSURE adds an additional closure slot
|
||||
|
||||
# Thank you, Python, for a such a well-thought out system that has
|
||||
# changed 4 or so times.
|
||||
# Thank you, Python: such a well-thought out system that has
|
||||
# changed and continues to change many times.
|
||||
|
||||
def build_param(ast, name, default):
|
||||
"""build parameters:
|
||||
- handle defaults
|
||||
- handle format tuple parameters
|
||||
"""
|
||||
if default:
|
||||
if self.version >= 3.6:
|
||||
value = default
|
||||
else:
|
||||
value = self.traverse(default, indent='')
|
||||
maybe_show_tree_param_default(self.showast, name, value)
|
||||
result = '%s=%s' % (name, value)
|
||||
if result[-2:] == '= ': # default was 'LOAD_CONST None'
|
||||
result += 'None'
|
||||
return result
|
||||
if self.version >= 3.6:
|
||||
value = default
|
||||
else:
|
||||
return name
|
||||
value = self.traverse(default, indent='')
|
||||
maybe_show_tree_param_default(self.showast, name, value)
|
||||
result = '%s=%s' % (name, value)
|
||||
|
||||
# The below can probably be removed. This is probably
|
||||
# a holdover from days when LOAD_CONST erroneously
|
||||
# didn't handle LOAD_CONST None properly
|
||||
if result[-2:] == '= ': # default was 'LOAD_CONST None'
|
||||
result += 'None'
|
||||
|
||||
return result
|
||||
|
||||
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
||||
assert node[-1].kind.startswith('MAKE_')
|
||||
@@ -552,8 +554,14 @@ def make_function3(self, node, is_lambda, nested=1, codeNode=None):
|
||||
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
||||
|
||||
# build parameters
|
||||
params = [build_param(ast, name, d) for
|
||||
name, d in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||
params = []
|
||||
if defparams:
|
||||
for i, defparam in enumerate(defparams):
|
||||
params.append(build_param(ast, paramnames[i], defparam))
|
||||
|
||||
params += paramnames[i+1:]
|
||||
else:
|
||||
params = paramnames
|
||||
|
||||
if not 3.0 <= self.version <= 3.1 or self.version >= 3.6:
|
||||
params.reverse() # back to correct order
|
||||
|
Reference in New Issue
Block a user