Correct kw+pos args semantics on 3.3

Sync fragment make_function code
This commit is contained in:
rocky
2016-06-19 21:41:40 -04:00
parent 8b50dda9ef
commit efb4012087
3 changed files with 23 additions and 8 deletions

Binary file not shown.

View File

@@ -1429,18 +1429,27 @@ class FragmentsWalker(pysource.SourceWalker, object):
else:
return name
# node[-1] == MAKE_FUNCTION_n
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
assert node[-1].type.startswith('MAKE_')
args_node = node[-1]
if isinstance(args_node.attr, tuple):
defparams = node[:args_node.attr[0]]
kw_args, annotate_args = args_node.attr
if self.version == 3.3:
# positional args are after kwargs
defparams = node[1:args_node.attr[0]+1]
else:
# positional args are before kwargs
defparams = node[:args_node.attr[0]]
pos_aargs, kw_args, annotate_args = args_node.attr
else:
defparams = node[:args_node.attr]
kw_args = (0, 0)
kw_args, annotate_args = (0, 0)
pass
code = node[code_index].attr
if self.version > 3.0 and isLambda and iscode(node[-3].attr):
code = node[-3].attr
else:
code = node[code_index].attr
assert iscode(code)
code = Code(code, self.scanner, self.currentclass)

View File

@@ -1697,11 +1697,17 @@ class SourceWalker(GenericASTTraversal, object):
else:
return name
# node[-1] == MAKE_FUNCTION_n
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
assert node[-1].type.startswith('MAKE_')
args_node = node[-1]
if isinstance(args_node.attr, tuple):
defparams = node[:args_node.attr[0]]
if self.version == 3.3:
# positional args are after kwargs
defparams = node[1:args_node.attr[0]+1]
else:
# positional args are before kwargs
defparams = node[:args_node.attr[0]]
pos_args, kw_args, annotate_args = args_node.attr
else:
defparams = node[:args_node.attr]
@@ -1785,7 +1791,7 @@ class SourceWalker(GenericASTTraversal, object):
self.mod_globs -= all_globals
rn = ('None' in code.co_names) and not find_none(ast)
self.gen_source(ast, code.co_name, code._customize, isLambda=isLambda,
returnNone=rn)
returnNone=rn)
code._tokens = None; code._customize = None # save memory
def build_class(self, code):