1717import cloudpickle as cp
1818from fileformats .core import FileSet
1919from pydra .utils .messenger import AuditFlag , Messenger
20- from pydra .utils .typing import TypeParser
20+ from pydra .utils .typing import TypeParser , is_optional , non_optional_type
2121from .helpers import (
2222 attrs_fields ,
2323 attrs_values ,
@@ -1100,6 +1100,7 @@ def _command_pos_args(
11001100 cmd_add = []
11011101 # formatter that creates a custom command argument
11021102 # it can take the value of the field, all inputs, or the value of other fields.
1103+ tp = non_optional_type (field .type ) if is_optional (field .type ) else field .type
11031104 if field .formatter :
11041105 call_args = inspect .getfullargspec (field .formatter )
11051106 call_args_val = {}
@@ -1121,20 +1122,20 @@ def _command_pos_args(
11211122 cmd_el_str = cmd_el_str .strip ().replace (" " , " " )
11221123 if cmd_el_str != "" :
11231124 cmd_add += split_cmd (cmd_el_str )
1124- elif field . type is bool and "{" not in field .argstr :
1125+ elif tp is bool and "{" not in field .argstr :
11251126 # if value is simply True the original argstr is used,
11261127 # if False, nothing is added to the command.
11271128 if value is True :
11281129 cmd_add .append (field .argstr )
1129- elif ty .get_origin (field . type ) is MultiInputObj :
1130+ elif ty .get_origin (tp ) is MultiInputObj :
11301131 # if the field is MultiInputObj, it is used to create a list of arguments
11311132 for val in value or []:
11321133 cmd_add += self ._format_arg (field , val )
11331134 else :
11341135 cmd_add += self ._format_arg (field , value )
11351136 return field .position , cmd_add
11361137
1137- def _format_arg (self , field : shell .arg , value : ty .Any ) -> list [str ]:
1138+ def _format_arg (self , field : shell .arg , value : ty .Any , tp : type ) -> list [str ]:
11381139 """Returning arguments used to specify the command args for a single inputs"""
11391140 if (
11401141 field .argstr .endswith ("..." )
0 commit comments