Hi, i am using imperative API's. in need of a clar...
# prefect-community
j
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
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
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
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
Thanks a lot !
c
anytime!
@Marvin archive “Issue with using kwargs in task run method”