Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes issues with super->sub-class auto-cast and handles MultiInputObj coercion #746

Merged
merged 9 commits into from
Jun 3, 2024
Prev Previous commit
Next Next commit
Update pydra/utils/typing.py
Co-authored-by: Chris Markiewicz <markiewicz@stanford.edu>
tclose and effigies authored May 30, 2024
commit ca0833cb6ab403c93dd2aaa0686840639f45821a
29 changes: 14 additions & 15 deletions pydra/utils/typing.py
Original file line number Diff line number Diff line change
@@ -551,21 +551,20 @@ def check_sequence(tp_args, pattern_args):
return expand_and_check(type_, self.pattern)
except TypeError as e:
# Special handling for MultiInputObjects (which are annoying)
if isinstance(self.pattern, tuple) and self.pattern[0] == MultiInputObj:
# Attempt to coerce the object into arg type of the MultiInputObj first,
# and if that fails, try to coerce it into a list of the arg type
inner_type_parser = copy(self)
inner_type_parser.pattern = self.pattern[1][0]
try:
inner_type_parser.check_type(type_)
except TypeError:
add_exc_note(
e,
"Also failed to coerce to the arg-type of the MultiInputObj "
f"({self.pattern[1][0]})",
)
raise e
else:
if not isinstance(self.pattern, tuple) or self.pattern[0] != MultiInputObj:
raise e
# Attempt to coerce the object into arg type of the MultiInputObj first,
# and if that fails, try to coerce it into a list of the arg type
inner_type_parser = copy(self)
inner_type_parser.pattern = self.pattern[1][0]
try:
inner_type_parser.check_type(type_)
except TypeError:
add_exc_note(
e,
"Also failed to coerce to the arg-type of the MultiInputObj "
f"({self.pattern[1][0]})",
)
raise e

def check_coercible(self, source: ty.Any, target: ty.Union[type, ty.Any]):