nipype / pydra

Pydra Dataflow Engine
https://nipype.github.io/pydra/
Other
119 stars 57 forks source link

TypeError: TypeParser doesn't know how to handle args ((<class 'pathlib.Path'>, <class 'NoneType'>)) for <class 'types.UnionType'> #744

Closed ghisvail closed 2 months ago

ghisvail commented 3 months ago

The following task definition:

@task
@annotate({"return": {"smoothed_image": Path}})
def smooth_image(input_image: Path, smoothed_image: Path | None) -> Path:
    ...

triggers an error:

TypeError: TypeParser doesn't know how to handle args ((<class 'pathlib.Path'>, <class 'NoneType'>)) for <class 'types.UnionType'> types in 'smoothed_image' field of Inputs

Notation X | None is becoming popular, and sometimes autoformatted by linters like Ruff. It would be great if Pydra's internal parsing mechanism were able to inject the necessary required / optional metadata to the fields, or at least not crash since this is a valid function definition.

tclose commented 3 months ago

This should be pretty straightforward

tclose commented 3 months ago

I have now implemented this functionality in the #742 PR

ghisvail commented 3 months ago

Reopened and added Closes attribute to the PR.