Merge pull request #38283 from tonytonev:fix-issue-36146
PiperOrigin-RevId: 305862026 Change-Id: I8743c9149867182f85978c59c2241c8591e4a0e2
This commit is contained in:
commit
9291eaa9a0
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user