File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -185,10 +185,15 @@ def extract_function_inputs_and_outputs(
185
185
input_defaults [p .name ] = p .default
186
186
if inputs is not None :
187
187
if not isinstance (inputs , dict ):
188
- raise ValueError (
189
- f"Input names ({ inputs } ) should not be provided when "
190
- "wrapping/decorating a function as "
191
- )
188
+ if non_named_args := [
189
+ i for i in inputs if not isinstance (i , Arg ) or i .name is None
190
+ ]:
191
+ raise ValueError (
192
+ "Only named Arg objects should be provided as inputs (i.e. not names or "
193
+ "other objects should not be provided when wrapping/decorating a "
194
+ f"function: found { non_named_args } when wrapping/decorating { function !r} "
195
+ )
196
+ inputs = {i .name : i for i in inputs }
192
197
if not has_varargs :
193
198
if unrecognised := set (inputs ) - set (input_types ):
194
199
raise ValueError (
Original file line number Diff line number Diff line change @@ -41,6 +41,26 @@ def func(function: ty.Callable) -> ty.Callable:
41
41
return function
42
42
43
43
44
+ def test_function_arg_fail2 ():
45
+
46
+ with pytest .raises (
47
+ ValueError , match = "Only named Arg objects should be provided as inputs"
48
+ ):
49
+
50
+ @python .define (inputs = [python .arg (help = "an int" )])
51
+ def func (a : int ) -> int :
52
+ return a * 2
53
+
54
+
55
+ def test_function_arg_add_help ():
56
+
57
+ @python .define (inputs = [python .arg (name = "a" , help = "an int" )])
58
+ def func (a : int ) -> int :
59
+ return a * 2
60
+
61
+ assert task_fields (func ).a .help == "an int"
62
+
63
+
44
64
def test_interface_wrap_function_with_default ():
45
65
def func (a : int , k : float = 2.0 ) -> float :
46
66
"""Sample function with inputs and outputs"""
Original file line number Diff line number Diff line change 21
21
22
22
logger = logging .getLogger ("pydra" )
23
23
if ty .TYPE_CHECKING :
24
- from pydra .compose .base import Task
24
+ from pydra .compose .base import Task , Field # noqa
25
25
from pydra .compose import workflow
26
26
27
27
You can’t perform that action at this time.
0 commit comments