# tf.TypeSpec

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L49-L546) |

Specifies a TensorFlow value type.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.TypeSpec`](https://www.tensorflow.org/api_docs/python/tf/TypeSpec), [`tf.compat.v1.data.experimental.Structure`](https://www.tensorflow.org/api_docs/python/tf/TypeSpec)

<br />

A [`tf.TypeSpec`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/TypeSpec) provides metadata describing an object accepted or returned
by TensorFlow APIs. Concrete subclasses, such as [`tf.TensorSpec`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/TensorSpec) and
[`tf.RaggedTensorSpec`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/RaggedTensorSpec), are used to describe different value types.

For example, [`tf.function`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/function)'s `input_signature` argument accepts a list
(or nested structure) of `TypeSpec`s.

Creating new subclasses of `TypeSpec` (outside of TensorFlow core) is not
currently supported. In particular, we may make breaking changes to the
private methods and properties defined by this base class.

#### Example:

    spec = tf.RaggedTensorSpec(shape=[None, None], dtype=tf.int32)
    @tf.function(input_signature=[spec])
    def double(x):
      return x * 2
    print(double(tf.ragged.constant([[1, 2], [3]])))
    <tf.RaggedTensor [[2, 4], [6]]>

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `value_type` | The Python type for values that are compatible with this TypeSpec. <br /> In particular, all values that are compatible with this TypeSpec must be an instance of this type. |

<br />

## Methods

### `is_compatible_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L103-L117)

    is_compatible_with(
        spec_or_value
    )

Returns true if `spec_or_value` is compatible with this TypeSpec.

### `most_specific_compatible_type`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L119-L141)

    most_specific_compatible_type(
        other: 'TypeSpec'
    ) -> 'TypeSpec'

Returns the most specific TypeSpec compatible with `self` and `other`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | A `TypeSpec`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If there is no TypeSpec that is compatible with both `self` and `other`. |

<br />

### `__eq__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L321-L324)

    __eq__(
        other
    ) -> bool

Return self==value.

### `__ne__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L326-L327)

    __ne__(
        other
    ) -> bool

Return self!=value.