You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
3.2 (and down to 3.0?) bug in fn name and kwargs
This commit is contained in:
20
test/simple_source/bug32/01_named_and_kwargs.py
Normal file
20
test/simple_source/bug32/01_named_and_kwargs.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# python 3.2 configparser.py
|
||||||
|
|
||||||
|
# Bug was emitting in 3.2
|
||||||
|
# def __init__(self, defaults=delimiters=('=', ':'),
|
||||||
|
# comment_prefixes=('#', ';'), inline_comment_prefixes=None,
|
||||||
|
# strict=True, empty_lines_in_values=True,
|
||||||
|
# default_section=DEFAULTSECT, interpolation=_UNSET, dict_type=None,
|
||||||
|
# allow_no_value=_default_dict, *, delimiters=('=', ':'),
|
||||||
|
# comment_prefixes=('#', ';'), inline_comment_prefixes=None,
|
||||||
|
# strict=True, empty_lines_in_values=True,
|
||||||
|
# default_section=DEFAULTSECT,
|
||||||
|
# interpolation=_UNSET):
|
||||||
|
|
||||||
|
def __init__(self, defaults=None, dict_type=_default_dict,
|
||||||
|
allow_no_value=False, *, delimiters=('=', ':'),
|
||||||
|
comment_prefixes=('#', ';'), inline_comment_prefixes=None,
|
||||||
|
strict=True, empty_lines_in_values=True,
|
||||||
|
default_section=DEFAULTSECT,
|
||||||
|
interpolation=_UNSET):
|
||||||
|
pass
|
@@ -2035,7 +2035,8 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
paramnames = list(code.co_varnames[:argc])
|
paramnames = list(code.co_varnames[:argc])
|
||||||
|
|
||||||
# defaults are for last n parameters, thus reverse
|
# defaults are for last n parameters, thus reverse
|
||||||
paramnames.reverse(); defparams.reverse()
|
if not 3.0 <= self.version <= 3.2:
|
||||||
|
paramnames.reverse(); defparams.reverse()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ast = self.build_ast(code._tokens,
|
ast = self.build_ast(code._tokens,
|
||||||
@@ -2047,29 +2048,46 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.ERROR = p
|
self.ERROR = p
|
||||||
return
|
return
|
||||||
|
|
||||||
# build parameters
|
|
||||||
params = [build_param(ast, name, default) for
|
|
||||||
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
|
|
||||||
|
|
||||||
params.reverse() # back to correct order
|
|
||||||
|
|
||||||
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
||||||
|
|
||||||
if 4 & code.co_flags: # flag 2 -> variable number of args
|
# build parameters
|
||||||
if self.version > 3.0:
|
if not 3.0 <= self.version <= 3.2:
|
||||||
params.append('*%s' % code.co_varnames[argc + kw_pairs])
|
params = [build_param(ast, name, default) for
|
||||||
else:
|
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||||
params.append('*%s' % code.co_varnames[argc])
|
params.reverse() # back to correct order
|
||||||
argc += 1
|
|
||||||
|
|
||||||
# dump parameter list (with default values)
|
if 4 & code.co_flags: # flag 2 -> variable number of args
|
||||||
indent = self.indent
|
if self.version > 3.0:
|
||||||
if isLambda:
|
params.append('*%s' % code.co_varnames[argc + kw_pairs])
|
||||||
self.write("lambda ", ", ".join(params))
|
else:
|
||||||
else:
|
params.append('*%s' % code.co_varnames[argc])
|
||||||
self.write("(", ", ".join(params))
|
argc += 1
|
||||||
|
|
||||||
|
# dump parameter list (with default values)
|
||||||
|
indent = self.indent
|
||||||
|
|
||||||
|
if isLambda:
|
||||||
|
self.write("lambda ", ", ".join(params))
|
||||||
|
else:
|
||||||
|
self.write("(", ", ".join(params))
|
||||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||||
|
|
||||||
|
else:
|
||||||
|
if isLambda:
|
||||||
|
self.write("lambda ")
|
||||||
|
else:
|
||||||
|
self.write("(")
|
||||||
|
i = len(paramnames) - len(defparams)
|
||||||
|
self.write(",".join(paramnames[:i]))
|
||||||
|
suffix = ', ' if i > 0 else ''
|
||||||
|
for n in node:
|
||||||
|
if n == 'pos_arg':
|
||||||
|
self.write(suffix)
|
||||||
|
self.write(paramnames[i] + '=')
|
||||||
|
i += 1
|
||||||
|
self.preorder(n)
|
||||||
|
suffix = ', '
|
||||||
|
|
||||||
if kw_args > 0:
|
if kw_args > 0:
|
||||||
if not (4 & code.co_flags):
|
if not (4 & code.co_flags):
|
||||||
if argc > 0:
|
if argc > 0:
|
||||||
@@ -2080,14 +2098,29 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
else:
|
else:
|
||||||
self.write(", ")
|
self.write(", ")
|
||||||
|
|
||||||
for n in node:
|
if not 3.0 <= self.version <= 3.2:
|
||||||
if n == 'pos_arg':
|
for n in node:
|
||||||
continue
|
if n == 'pos_arg':
|
||||||
elif self.version >= 3.4 and n.type != 'kwargs':
|
continue
|
||||||
continue
|
elif self.version >= 3.4 and n.type != 'kwargs':
|
||||||
else:
|
continue
|
||||||
self.preorder(n)
|
else:
|
||||||
break
|
self.preorder(n)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
kwargs = node[0]
|
||||||
|
last = len(kwargs)-1
|
||||||
|
i = 0
|
||||||
|
for n in node[0]:
|
||||||
|
if n == 'kwarg':
|
||||||
|
self.write('%s=' % n[0].pattr)
|
||||||
|
self.preorder(n[1])
|
||||||
|
if i < last:
|
||||||
|
self.write(', ')
|
||||||
|
i += 1
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if 8 & code.co_flags: # flag 3 -> keyword args
|
if 8 & code.co_flags: # flag 3 -> keyword args
|
||||||
|
Reference in New Issue
Block a user