@@ -151,25 +151,21 @@ def template_update_single(
151
151
# if input_dict_st with state specific value is not available,
152
152
# the dictionary will be created from inputs object
153
153
from ..utils .typing import TypeParser # noqa
154
- from pydra .engine .specs import LazyField
155
-
156
- VALID_TYPES = (str , ty .Union [str , bool ], Path , ty .Union [Path , bool ], LazyField )
154
+ from pydra .engine .specs import LazyField , OUTPUT_TEMPLATE_TYPES
157
155
158
156
if inputs_dict_st is None :
159
157
inputs_dict_st = attr .asdict (inputs , recurse = False )
160
158
161
159
if spec_type == "input" :
162
160
inp_val_set = inputs_dict_st [field .name ]
163
- if inp_val_set is not attr .NOTHING and not TypeParser .is_instance (
164
- inp_val_set , VALID_TYPES
165
- ):
166
- raise TypeError (
167
- f"'{ field .name } ' field has to be a Path instance or a bool, but { inp_val_set } set"
168
- )
169
161
if isinstance (inp_val_set , bool ) and field .type in (Path , str ):
170
162
raise TypeError (
171
163
f"type of '{ field .name } ' is Path, consider using Union[Path, bool]"
172
164
)
165
+ if inp_val_set is not attr .NOTHING and not isinstance (LazyField ):
166
+ inp_val_set = TypeParser (ty .Union .__getitem__ (OUTPUT_TEMPLATE_TYPES ))(
167
+ inp_val_set
168
+ )
173
169
elif spec_type == "output" :
174
170
if not TypeParser .contains_type (FileSet , field .type ):
175
171
raise TypeError (
@@ -179,22 +175,23 @@ def template_update_single(
179
175
else :
180
176
raise TypeError (f"spec_type can be input or output, but { spec_type } provided" )
181
177
# for inputs that the value is set (so the template is ignored)
182
- if spec_type == "input" and isinstance (inputs_dict_st [field .name ], (str , Path )):
183
- return inputs_dict_st [field .name ]
184
- elif spec_type == "input" and inputs_dict_st [field .name ] is False :
185
- # if input fld is set to False, the fld shouldn't be used (setting NOTHING)
186
- return attr .NOTHING
187
- else : # inputs_dict[field.name] is True or spec_type is output
188
- value = _template_formatting (field , inputs , inputs_dict_st )
189
- # changing path so it is in the output_dir
190
- if output_dir and value is not attr .NOTHING :
191
- # should be converted to str, it is also used for input fields that should be str
192
- if type (value ) is list :
193
- return [str (output_dir / Path (val ).name ) for val in value ]
194
- else :
195
- return str (output_dir / Path (value ).name )
196
- else :
178
+ if spec_type == "input" :
179
+ if isinstance (inp_val_set , (Path , list )):
180
+ return inp_val_set
181
+ if inp_val_set is False :
182
+ # if input fld is set to False, the fld shouldn't be used (setting NOTHING)
197
183
return attr .NOTHING
184
+ # inputs_dict[field.name] is True or spec_type is output
185
+ value = _template_formatting (field , inputs , inputs_dict_st )
186
+ # changing path so it is in the output_dir
187
+ if output_dir and value is not attr .NOTHING :
188
+ # should be converted to str, it is also used for input fields that should be str
189
+ if type (value ) is list :
190
+ return [str (output_dir / Path (val ).name ) for val in value ]
191
+ else :
192
+ return str (output_dir / Path (value ).name )
193
+ else :
194
+ return attr .NOTHING
198
195
199
196
200
197
def _template_formatting (field , inputs , inputs_dict_st ):
0 commit comments