Skip to content

Commit 6397e85

Browse files
committed
reverted relaxation of parent->child type checking as it will be a bit more involved. Will add in separate PR
1 parent d2ed9a0 commit 6397e85

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pydra/utils/tests/test_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def test_matches_type_dict():
474474

475475
def test_matches_type_type():
476476
assert TypeParser.matches_type(type, type)
477-
assert not TypeParser.matches_type(object, type)
477+
assert not TypeParser.matches_type(int, type)
478478

479479

480480
def test_matches_type_tuple():

pydra/utils/typing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def coerce_obj(obj, type_):
289289
if obj is not object_
290290
else ""
291291
)
292-
raise TypeError(f"Cannot coerce {obj} into {type_}{msg}") from e
292+
raise TypeError(f"Cannot coerce {obj!r} into {type_}{msg}") from e
293293

294294
return expand_and_coerce(object_, self.pattern)
295295

@@ -352,7 +352,7 @@ def check_basic(tp, target):
352352
# Note that we are deliberately more permissive than typical type-checking
353353
# here, allowing parents of the target type as well as children,
354354
# to avoid users having to cast from loosely typed tasks to strict ones
355-
if not self.is_subclass(tp, target) and not self.is_subclass(target, tp):
355+
if not self.is_subclass(tp, target):
356356
self.check_coercible(tp, target)
357357

358358
def check_union(tp, pattern_args):
@@ -369,7 +369,8 @@ def check_union(tp, pattern_args):
369369
break
370370
if reasons:
371371
raise TypeError(
372-
f"Cannot coerce {tp} to ty.Union[{', '.join(pattern_args)}], "
372+
f"Cannot coerce {tp} to "
373+
f"ty.Union[{', '.join(str(a) for a in pattern_args)}], "
373374
f"because {tp_arg} cannot be coerced to any of its args:\n\n"
374375
+ "\n\n".join(
375376
f"{a} -> {e}" for a, e in zip(pattern_args, reasons)

0 commit comments

Comments
 (0)