Skip to content

Commit 1ec1933

Browse files
committed
added guards for arguments name clashes with 'function', 'executable', 'constructor'
1 parent 932fc3f commit 1ec1933

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

pydra/design/python.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def make(wrapped: ty.Callable | type) -> PythonDef:
159159
input_helps=input_helps,
160160
output_helps=output_helps,
161161
)
162+
if "function" in parsed_inputs:
163+
raise ValueError(
164+
"The argument 'function' is reserved for a field to hold the function "
165+
"to be wrapped"
166+
)
162167

163168
parsed_inputs["function"] = arg(
164169
name="function", type=ty.Callable, default=function, hash_eq=True

pydra/design/shell.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ def make(
383383
{n: getattr(ShellOutputs, n) for n in ShellOutputs.BASE_NAMES}
384384
)
385385

386+
if "executable" in parsed_inputs:
387+
raise ValueError(
388+
"The argument 'executable' is reserved for a field to hold the command "
389+
"to be run"
390+
)
391+
386392
# Update the inputs (overriding inputs from base classes) with the executable
387393
# and the output argument fields
388394
parsed_inputs.update(

pydra/design/tests/test_python.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def func(a: int) -> float:
3333
SampleDef(a=1.5)
3434

3535

36+
def test_function_arg_fail():
37+
38+
with pytest.raises(ValueError, match="The argument 'function' is reserved"):
39+
40+
@python.define
41+
def func(function: ty.Callable) -> ty.Callable:
42+
return function
43+
44+
3645
def test_interface_wrap_function_with_default():
3746
def func(a: int, k: float = 2.0) -> float:
3847
"""Sample function with inputs and outputs"""

pydra/design/tests/test_shell.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def test_interface_template():
6666
Cp.Outputs(out_path=File.mock("in-path.txt"))
6767

6868

69+
def test_executable_arg_fail():
70+
71+
with pytest.raises(ValueError, match="The argument 'executable' is reserved"):
72+
73+
shell.define("my-cmd <executable>")
74+
75+
6976
def test_interface_template_w_types_and_path_template_ext():
7077

7178
TrimPng = shell.define("trim-png <in_image:image/png> <out|out_image:image/png>")

pydra/design/tests/test_workflow.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from operator import attrgetter
22
from copy import copy
33
from unittest.mock import Mock
4+
import pytest
45
import attrs
56
from pydra.engine.lazy import LazyInField, LazyOutField
67
import typing as ty
@@ -74,6 +75,15 @@ def MyTestWorkflow(a, b):
7475
assert list(wf.node_names) == ["Add", "Mul"]
7576

7677

78+
def test_constructor_arg_fail():
79+
80+
with pytest.raises(ValueError, match="The argument 'constructor' is reserved"):
81+
82+
@workflow.define
83+
def MyTestWorkflow(constructor: ty.Callable) -> ty.Callable:
84+
return constructor
85+
86+
7787
def test_shell_workflow():
7888

7989
@workflow.define(outputs=["output_video"])

pydra/design/workflow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def make(wrapped: ty.Callable | type) -> TaskDef:
169169
output_helps=output_helps,
170170
)
171171

172+
if "constructor" in parsed_inputs:
173+
raise ValueError(
174+
"The argument 'constructor' is reserved and cannot be used as an "
175+
"argument name"
176+
)
177+
172178
parsed_inputs["constructor"] = arg(
173179
name="constructor", type=ty.Callable, hash_eq=True, default=constructor
174180
)

0 commit comments

Comments
 (0)