def check_fold_arguments_list_inputs(self, func, args, kws): def make_tuple(*args): return args unused_handler = None pysig = utils.pysignature(func) names = list(pysig.parameters) with self.subTest(kind='dict'): folded_dict = typing.fold_arguments( pysig, args, kws, make_tuple, unused_handler, unused_handler, ) # correct ordering for i, (j, k) in enumerate(zip(folded_dict, names)): (got_index, got_param, got_name) = j self.assertEqual(got_index, i) self.assertEqual(got_name, f'arg.{k}') kws = list(kws.items()) with self.subTest(kind='list'): folded_list = typing.fold_arguments( pysig, args, kws, make_tuple, unused_handler, unused_handler, ) self.assertEqual(folded_list, folded_dict)
def fold_call_args(self, fnty, signature, pos_args, vararg, kw_args): if vararg: # Inject *args from function call # The lowering will be done in _cast_var() above. tp_vararg = self.typeof(vararg.name) assert isinstance(tp_vararg, types.BaseTuple) pos_args = pos_args + [ _VarArgItem(vararg, i) for i in range(len(tp_vararg)) ] # Fold keyword arguments and resolve default argument values pysig = signature.pysig if pysig is None: if kw_args: raise NotImplementedError("unsupported keyword arguments " "when calling %s" % (fnty, )) argvals = [ self._cast_var(var, sigty) for var, sigty in zip(pos_args, signature.args) ] else: def normal_handler(index, param, var): return self._cast_var(var, signature.args[index]) def default_handler(index, param, default): return self.context.get_constant_generic( self.builder, signature.args[index], default) def stararg_handler(index, param, vars): stararg_ty = signature.args[index] assert isinstance(stararg_ty, types.BaseTuple), stararg_ty values = [ self._cast_var(var, sigty) for var, sigty in zip(vars, stararg_ty) ] return cgutils.make_anonymous_struct(self.builder, values) argvals = typing.fold_arguments(pysig, pos_args, dict(kw_args), normal_handler, default_handler, stararg_handler) return argvals