Improve error messages for IterativeProcess by making types easier to compare. This change puts each type on a fresh newline so they "line up", and prints the actual next_result_type rather than the full type in which it is embedded.
@@ -275,23 +275,22 @@ class IterativeProcess(object):
if initialize_result_type != next_first_param_type:
raise TypeError('The return type of initialize_fn should match the '
'first parameter of next_fn, but found\n'
- 'initialize_fn.type_signature.result={}\n'
- 'next_fn.type_signature.parameter[0]={}'.format(
+ 'initialize_fn.type_signature.result=\n{}\n'
+ 'next_fn.type_signature.parameter[0]=\n{}'.format(
initialize_result_type, next_first_param_type))
next_result_type = next_fn.type_signature.result
if next_first_param_type != next_result_type:
# This might be multiple output next_fn, check if the first argument might
- # be the state. If still not the right type, raise and error.
+ # be the state. If still not the right type, raise an error.
if isinstance(next_result_type, tff.NamedTupleType):
next_result_type = next_result_type[0]
if next_first_param_type != next_result_type:
raise TypeError('The return type of next_fn should match the '
'first parameter, but found\n'
- 'next_fn.type_signature.parameter[0]={}\n'
- 'next_fn.type_signature.result={}'.format(
- next_first_param_type,
- next_fn.type_signature.result))
+ 'next_fn.type_signature.parameter[0]=\n{}\n'
+ 'actual next_result_type=\n{}'.format(
+ next_first_param_type, next_result_type))
self._initialize_fn = initialize_fn
self._next_fn = next_fn
