Hey everyone. Just a quick question. Does someone ...
# ask-the-community
j
Hey everyone. Just a quick question. Does someone know if there is the a proper way to handle keywordarguments with tasks:
Copy code
@task
def test(a, b, c):
    return a+b+c

@workflow
def workflow_test():
    kwargs = {"a": 4, "b": 3, "c":0}
    test(**kwargs)
Thanks already!
j
i think what you have should work right? do you want to return a dict and give that to the next task since just having the hard coded values here is not very useful
j
You are right. My example was a bit off. Let me draw a better one:
Copy code
@task
def task1():
    return {"a": 4, "b": 3, "c":0}

@task
def task2(a, b, c):
    return a+b+c

@workflow
def workflow_test():
    kwargs = task1()
    task2(**kwargs)
Basically lets say task1 returns a dictionary with optimal parameters for initating task2.
Since the kwargs returned will be a Promise it basically cant be used in this way
j
yeah, what we have for this case was just return a
dict
and recieve a dict like this
Copy code
def my_task(task_params: dict):
and return
dict ->:
in other task, well we dont do exactly what you have in your example but it should work
j
Okay so if I understand you correcty you then map the parameters from the dict inside the function?
j
yup `MyObject(**task_params)`and use the object
j
I see thanks a lot!
151 Views