pydra icon indicating copy to clipboard operation
pydra copied to clipboard

Task argument keys should be checked against inputspec for typos

Open satra opened this issue 5 years ago • 5 comments

at present if i generate a typo in the kwarg assigned when running a task, i have to wait till task execution to know an error has happened. this should be checked at task initialization time.

@pydra.mark.task
def func(aa, ac):
    return 1

func(ab=2)  # this should raise a KeyError exception

satra avatar May 17 '20 13:05 satra

KeyError would seem to be exposing an implementation detail. My expectation would be a TypeError:

>>> def func(aa, ac):
...     return 1

>>> func(ab=2)
TypeError: func() got an unexpected keyword argument 'ab'

I'm not sure if this is rehashing an already had discussion, but I would generally try to be as similar to vanilla Python in behavior as possible.

effigies avatar May 17 '20 15:05 effigies

@satra want to confirm should an error only be raised whenever a task is initialized, or only when the task is not part of a workflow? Or there only be an error when none of the argument name matches the one defined in the function?

nicolocin avatar May 21 '20 16:05 nicolocin

whenever a task is initialized or run, since there are two ways of sending inputs to a task during init and in _run. i think both should check for the correct inputs. currently this is being done with attr.evolve

satra avatar May 21 '20 22:05 satra

thanks again for all your effort. Pydra shows great promise!

@satra @nicolocin @djarecka What is the current state on this issue? It actually caused me numerous headaches to debug workflows where I had mistyped a single function keyword argument and got weird errors down the line. I also feel like I was only able to debug these issues, due to my elevated programming experience. This makes it difficult to recommend pydra (over nipype) to unexperienced users, although I find the general syntax a lot more user-friendly when compared to nipype. I also agree with @effigies, that an immediate TypeError would be the most pythonic way to handle this situation. Automatic systems like the code checking in PyCharm are unable to catch typos when the @task decorator is involved, being another argument for throwing that error as early as possible.

If there hasn't been any progress on this issue, I will try to come up with a proposal within the next days.

dafrose avatar Apr 05 '22 11:04 dafrose

I don't think we've worked on this recently, so a contribution would be welcome.

effigies avatar Apr 05 '22 11:04 effigies