Skip to content

Commit 3aad031

Browse files
authored
Merge pull request #794 from nipype/bugfix-task-eq
Bugfix-task-eq
2 parents 4235306 + 0e29abb commit 3aad031

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pydra/compose/base/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ def __iter__(self) -> ty.Generator[str, None, None]:
404404
def __eq__(self, other: ty.Any) -> bool:
405405
"""Check if two tasks are equal"""
406406
values = attrs.asdict(self, recurse=False)
407+
if not isinstance(other, Task):
408+
return False
407409
try:
408410
other_values = attrs.asdict(other, recurse=False)
409411
except AttributeError:

pydra/compose/tests/test_python_equivalence.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,13 @@ def Square(in_val):
237237
outputs = Square(in_val=2.0)()
238238
assert outputs.squared == 4.0
239239
assert outputs.cubed == 8.0
240+
241+
242+
def test_non_task_eq():
243+
"""Checks tasks can be compared to non-tasks"""
244+
245+
@python.define
246+
def Square(in_val):
247+
return in_val**2, in_val**3
248+
249+
assert Square(in_val=1) != 42

0 commit comments

Comments
 (0)