Skip to content

Commit 0debfd4

Browse files
Jan MatějkaJan Matějka
authored andcommitted
Print the expected thing and got thing
1 parent 7a3bffb commit 0debfd4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

annotation/typed.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,18 @@ def _check_argument_types(signature, *args, **kwargs):
466466
if not _check_type_constraint(value, annotation):
467467
raise TypeError('Incorrect type for "{0}"'.format(name))
468468

469+
class IncorrectReturnType(TypeError): pass
469470

470471
def _check_return_type(signature, return_value):
471472
"""Check that the return value of a function matches the signature."""
472473
annotation = signature.return_annotation
473474
if annotation is EMPTY_ANNOTATION:
474475
annotation = AnyType
475476
if not _check_type_constraint(return_value, annotation):
476-
raise TypeError('Incorrect return type')
477+
raise IncorrectReturnType('Expected: {0!r} Got: {1!r}'.format(
478+
annotation
479+
, return_value
480+
))
477481
return return_value
478482

479483

0 commit comments

Comments
 (0)