def _resolve_named_dims(shape: Sequence[Union[int, Text]],
                        named_dims: Dict[Text, Union[tf.Tensor, int]],
                        tensor_name: Text,
                        func_name: Text) -> Sequence[Union[int, tf.Tensor]]:
  """Resolves the name of any named dimensions and returns the scalar value."""
  numeric_shape: List[Union[int, tf.Tensor]] = list()
  for dim in shape:
    if isinstance(dim, str):
      numeric_dim = named_dims.get(dim, None)
      if numeric_dim is None:
        raise ValueError(
            "Named dimension `{}` not defined as `NamedDim` in "
            "contract when expanding checks for tensor `{}` "
            "in function `{}`. Have NamedDims: {}"
            .format(dim, tensor_name, func_name, " ".join(named_dims.keys())))

      numeric_shape.append(numeric_dim)
    else:
      numeric_shape.append(dim)
  return numeric_shape
Resolves the name of any named dimensions and returns the scalar value.
language/canine/tensor_contracts.py