02/25/2022, 9:31 PM
Is it possible to map over kwargs as asked in this Q&A? Context: I’m trying to create a cross-product of multiple lists to map over. I want to operate on the downstream values by taking them as kwargs. Inspiration from this question answered by @Kevin Kho
from prefect import Flow, task
from pprint import pformat

def numbers():
    return [1, 2]

def letters():
    return ["a", "b", "c"]

def cross_product(numbers, letters):
    res = []
    for letter in letters:
        for num in numbers:
            res.append({"num": num, "letter": letter})
    return res

def pretty_print(**kwargs):

with Flow("...") as flow:
    n = numbers()
    l = letters()
    map_items = cross_product(n, l)
I get the following error:
Traceback (most recent call last):
  File "", line 33, in <module>
  File "prefect/core/", line 760, in map
    *args, mapped=True, upstream_tasks=upstream_tasks, flow=flow, **kwargs
  File "prefect/core/", line 674, in bind
    callargs = dict(signature.bind(*args, **kwargs).arguments)  # type: Dict
  File "", line 3015, in bind
    return args[0]._bind(args[1:], kwargs)
  File "", line 2942, in _bind
    'too many positional arguments') from None
TypeError: too many positional arguments

Kevin Kho

02/25/2022, 9:34 PM
I believe you really just can’t do it for **kwargs but I think you can just accept the dict and then work with that right?


02/25/2022, 9:49 PM
yeah we could use it just as an
dictionary. Can we dynamically rename the task with
task_run_name="number: {items[num]} letter: {items[letter]}"
is that just a format string?

Kevin Kho

02/25/2022, 9:50 PM
Someone told me it worked if items is the name of the input into the task