Skip to content

Commit 59bd130

Browse files
authored
Merge pull request #842 from nipype/subclass-or-union
generalize is_fileset_or_union utility to is_subclass_or_union
2 parents fc3a6ce + 39478a0 commit 59bd130

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

pydra/environments/docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Docker(base.Container):
1515
def execute(self, job: "Job[shell.Task]") -> dict[str, ty.Any]:
1616
docker_img = f"{self.image}:{self.tag}"
1717
# mounting all input locations
18-
mounts, values = self.get_bindings(job=job, root=self.root)
18+
mounts, arg_values = self.get_bindings(job=job, root=self.root)
1919

2020
docker_args = [
2121
"docker",
@@ -32,7 +32,7 @@ def execute(self, job: "Job[shell.Task]") -> dict[str, ty.Any]:
3232

3333
job.cache_dir.mkdir(exist_ok=True)
3434
values = base.execute(
35-
docker_args + [docker_img] + job.task._command_args(values=values),
35+
docker_args + [docker_img] + job.task._command_args(values=arg_values),
3636
)
3737
output = dict(zip(keys, values))
3838
if output["return_code"]:

pydra/utils/typing.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def check_union(tp, pattern_args):
527527
except TypeError as e:
528528
reasons.append(e)
529529
else:
530-
reasons = None
530+
reasons = []
531531
break
532532
if self.match_any_of_union and len(reasons) < len(tp_args):
533533
# Just need one of the union args to match
@@ -1122,16 +1122,42 @@ def is_fileset_or_union(type_: type, allow_none: bool | None = None) -> bool:
11221122
is_fileset : bool
11231123
whether the type is a FileSet or a Union containing a FileSet
11241124
"""
1125+
return is_subclass_or_union(type_, core.FileSet, allow_none=allow_none)
1126+
1127+
1128+
def is_subclass_or_union(
1129+
type_: type, reference: type, allow_none: bool | None = None
1130+
) -> bool:
1131+
"""Check if the type is a subclass of given reference or a Union containing
1132+
that reference type
1133+
1134+
Parameters
1135+
----------
1136+
type_ : type
1137+
the type to check
1138+
reference : type
1139+
the reference type to check whether the type is a sub-class of or not
1140+
allow_none : bool, optional
1141+
whether to allow None as a valid type, by default None. If None, then None
1142+
is not allowed at the outer layer, but is allowed within a Union
1143+
1144+
Returns
1145+
-------
1146+
bool
1147+
whether the type is a FileSet or a Union containing a FileSet
1148+
"""
11251149
if type_ is None and allow_none:
11261150
return True
11271151
if is_union(type_):
11281152
return any(
1129-
is_fileset_or_union(t, allow_none=allow_none or allow_none is None)
1153+
is_subclass_or_union(
1154+
t, reference, allow_none=allow_none or allow_none is None
1155+
)
11301156
for t in ty.get_args(type_)
11311157
)
11321158
elif not inspect.isclass(type_):
11331159
return False
1134-
return issubclass(type_, core.FileSet)
1160+
return issubclass(type_, reference)
11351161

11361162

11371163
def is_type(*args: ty.Any) -> bool:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ doc = [
5757
"packaging",
5858
"pandas",
5959
"pandoc",
60-
"pydra-mrtrix3 >=3.0.4a17",
60+
"pydra-tasks-mrtrix3 >=3.1.0a1",
6161
"scipy",
6262
"sphinx",
6363
"sphinx-argparse",
@@ -100,7 +100,7 @@ tutorial = [
100100
"openneuro-py",
101101
"pandas",
102102
"psutil",
103-
"pydra-mrtrix3 >=3.0.4a17",
103+
"pydra-tasks-mrtrix3 >=3.1.0a1",
104104
"scipy",
105105
"sh",
106106
]

0 commit comments

Comments
 (0)