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

Fix issue 36146 #38283

Merged
merged 6 commits into from
Apr 10, 2020
11 changes: 9 additions & 2 deletions tensorflow/python/util/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ def _sequence_like(instance, args):
instance_type = type(instance)
tf_logging.log_first_n(
tf_logging.WARN, "Mapping types may not work well with tf.nest. Prefer"
"using MutableMapping for {}".format(instance_type), 1)
return instance_type((key, result[key]) for key in instance)
" using MutableMapping for {}".format(instance_type), 1)
try:
return instance_type((key, result[key]) for key in instance)
except TypeError as err:
raise TypeError("Error creating an object of type {} like {}. Note that "
"it must accept a single positional argument "
"representing an iterable of key-value pairs, in "
"addition to self. Cause: {}".format(type(instance),
instance, err))
elif _is_mapping_view(instance):
# We can't directly construct mapping views, so we create a list instead
return list(args)
Expand Down