@@ -289,7 +289,7 @@ def coerce_obj(obj, type_):
289
289
if obj is not object_
290
290
else ""
291
291
)
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
293
293
294
294
return expand_and_coerce (object_ , self .pattern )
295
295
@@ -352,7 +352,7 @@ def check_basic(tp, target):
352
352
# Note that we are deliberately more permissive than typical type-checking
353
353
# here, allowing parents of the target type as well as children,
354
354
# 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 ):
356
356
self .check_coercible (tp , target )
357
357
358
358
def check_union (tp , pattern_args ):
@@ -369,7 +369,8 @@ def check_union(tp, pattern_args):
369
369
break
370
370
if reasons :
371
371
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 )} ], "
373
374
f"because { tp_arg } cannot be coerced to any of its args:\n \n "
374
375
+ "\n \n " .join (
375
376
f"{ a } -> { e } " for a , e in zip (pattern_args , reasons )
0 commit comments