parameters: (instance, args)
docstring: Converts the sequence `args` to the same type as `instance`.
  
    Args:
      instance: an instance of `tuple`, `list`, `namedtuple`, `dict`,
          `collections.OrderedDict`, or `composite_tensor.Composite_Tensor`
          or `type_spec.TypeSpec`.
      args: elements to be converted to the `instance` type.
  
    Returns:
      `args` with the type of `instance`.
docstring_summary: Converts the sequence `args` to the same type as `instance`.
docstring_tokens: Converts the sequence args to the same type as instance .
function: def _sequence_like(instance, args):
    """Converts the sequence `args` to the same type as `instance`.
  
    Args:
      instance: an instance of `tuple`, `list`, `namedtuple`, `dict`,
          `collections.OrderedDict`, or `composite_tensor.Composite_Tensor`
          or `type_spec.TypeSpec`.
      args: elements to be converted to the `instance` type.
  
    Returns:
      `args` with the type of `instance`.
    """
    if _is_mapping(instance):
      # Pack dictionaries in a deterministic order by sorting the keys.
      # Notice this means that we ignore the original order of `OrderedDict`
      # instances. This is intentional, to avoid potential bugs caused by mixing
      # ordered and plain dicts (e.g., flattening a dict but using a
      # corresponding `OrderedDict` to pack it back).
      result = dict(zip(_sorted(instance), args))
      instance_type = type(instance)
      if instance_type == _collections.defaultdict:
        d = _collections.defaultdict(instance.default_factory)
        for key in instance:
          d[key] = result[key]
        return d
      else:
        return instance_type((key, result[key]) for key in instance)
    if _is_mapping_view(instance):
      # We can't directly construct mapping views, so we create a list instead
      return list(args)
    elif _is_namedtuple(instance) or _is_attrs(instance):
      return type(instance)(*args)
    elif _is_composite_tensor(instance):
      assert len(args) == 1
      spec = instance._type_spec  # pylint: disable=protected-access
      return spec._from_components(args[0])  # pylint: disable=protected-access
    elif _is_type_spec(instance):
      # Pack a CompositeTensor's components according to a TypeSpec.
      assert len(args) == 1
      return instance._from_components(args[0])  # pylint: disable=protected-access
    elif isinstance(instance, _six.moves.range):
      return _sequence_like(list(instance), args)
    else:
      # Not a namedtuple
      return type(instance)(args)
function_tokens: def _sequence_like ( instance , args ) : if _is_mapping ( instance ) : # Pack dictionaries in a deterministic order by sorting the keys. # Notice this means that we ignore the original order of `OrderedDict` # instances. This is intentional, to avoid potential bugs caused by mixing # ordered and plain dicts (e.g., flattening a dict but using a # corresponding `OrderedDict` to pack it back). result = dict ( zip ( _sorted ( instance ) , args ) ) instance_type = type ( instance ) if instance_type == _collections . defaultdict : d = _collections . defaultdict ( instance . default_factory ) for key in instance : d [ key ] = result [ key ] return d else : return instance_type ( ( key , result [ key ] ) for key in instance ) if _is_mapping_view ( instance ) : # We can't directly construct mapping views, so we create a list instead return list ( args ) elif _is_namedtuple ( instance ) or _is_attrs ( instance ) : return type ( instance ) ( * args ) elif _is_composite_tensor ( instance ) : assert len ( args ) == 1 spec = instance . _type_spec # pylint: disable=protected-access return spec . _from_components ( args [ 0 ] ) # pylint: disable=protected-access elif _is_type_spec ( instance ) : # Pack a CompositeTensor's components according to a TypeSpec. assert len ( args ) == 1 return instance . _from_components ( args [ 0 ] ) # pylint: disable=protected-access elif isinstance ( instance , _six . moves . range ) : return _sequence_like ( list ( instance ) , args ) else : # Not a namedtuple return type ( instance ) ( args )