https://prefect.io logo
j

Joselin

07/08/2019, 6:58 AM
Hi, i am using imperative API's. in need of a clarification on using kwargs in overridden Task class run method. Am using two classes and i want to pass kwargs to one and the modified kwargs to the next task. Am not sure if i had done right in putting pieces together but am getting "TypeError: too many positional arguments" from the second class's run method. I have attached the code as well. Thanks in Advance
c

Chris White

07/08/2019, 2:47 PM
hi @Joselin - when you call your second
iseven
task, you are using a positional argument:
Copy code
iseven.bind(res, flow=kw_flow)
you will need to refactor your
IsEven
run method to accept a dictionary of keyword arguments as a named argument, like:
Copy code
def run(self, kwargs):
and then call it with that keyword:
Copy code
iseven.bind(kwargs=res, flow=kw_flow)
👍 1
actually, if you make the exact change to the
run
method that I proposed, you can continue to use a positional argument
j

Joselin

07/09/2019, 5:40 AM
So, it's like am passing a dictionary as a param to IsEven run method. But pycharm keeps showing this "Signature of method IsEven.run() does not match the signature of the base method in class 'Task' ". Is there any possibility to avoid this warning ?
c

Chris White

07/09/2019, 12:56 PM
I’m not super familiar with pycharm settings but in this case we never expect the run method to have the same signature as the base method - the run method is intended to be overwritten
👍 1
j

Joselin

07/10/2019, 5:53 AM
Thanks a lot !
c

Chris White

07/10/2019, 2:50 PM
anytime!
@Marvin archive “Issue with using kwargs in task run method”
8 Views