Skip to content

Commit 4e4c6a4

Browse files
committed
move all aliases to _aliases.pyi
1 parent 79e09df commit 4e4c6a4

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

stubs/tensorflow/tensorflow/__init__.pyi

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from contextlib import contextmanager
66
from enum import Enum
77
from types import TracebackType
88
from typing import Any, Generic, NoReturn, TypeVar, overload
9-
from typing_extensions import ParamSpec, Self, TypeAlias
9+
from typing_extensions import ParamSpec, Self
1010

1111
import numpy
1212
from google.protobuf.message import Message
@@ -19,7 +19,17 @@ from tensorflow import (
1919
keras as keras,
2020
math as math,
2121
)
22-
from tensorflow._aliases import _ContainerGradients, _ContainerTensors, _ContainerTensorsLike, _Gradients, _TensorLike
22+
from tensorflow._aliases import (
23+
_ContainerGradients,
24+
_ContainerTensors,
25+
_ContainerTensorsLike,
26+
_DTypeLike,
27+
_Gradients,
28+
_ShapeLike,
29+
_Slice,
30+
_TensorCompatible,
31+
_TensorLike,
32+
)
2333
from tensorflow.core.protobuf import struct_pb2
2434

2535
# Explicit import of DType is covered by the wildcard, but
@@ -73,15 +83,6 @@ from tensorflow.sparse import SparseTensor as SparseTensor
7383
# we will skip making Tensor generic. Also good type hints for shapes will
7484
# run quickly into many places where type system is not strong enough today.
7585
# So shape typing is probably not worth doing anytime soon.
76-
_Slice: TypeAlias = int | slice | None
77-
78-
_FloatDataSequence: TypeAlias = Sequence[float] | Sequence[_FloatDataSequence]
79-
_StrDataSequence: TypeAlias = Sequence[str] | Sequence[_StrDataSequence]
80-
_ScalarTensorCompatible: TypeAlias = Tensor | str | float | numpy.ndarray[Any, Any] | numpy.number[Any]
81-
_TensorCompatible: TypeAlias = _ScalarTensorCompatible | Sequence[_TensorCompatible]
82-
_ShapeLike: TypeAlias = TensorShape | Iterable[_ScalarTensorCompatible | None] | int | Tensor
83-
_DTypeLike: TypeAlias = DType | str | numpy.dtype[Any]
84-
8586
class Tensor:
8687
def __init__(self, op: Operation, value_index: int, dtype: DType) -> None: ...
8788
def consumers(self) -> list[Incomplete]: ...

stubs/tensorflow/tensorflow/_aliases.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ _T = TypeVar("_T")
1414
_ContainerGeneric: TypeAlias = Mapping[str, _ContainerGeneric[_T]] | Sequence[_ContainerGeneric[_T]] | _T
1515

1616
_TensorLike: TypeAlias = tf.Tensor | tf.RaggedTensor | tf.SparseTensor
17-
_SparseTensorLike: TypeAlias = tf.Tensor | tf.SparseTensor
18-
_RaggedTensorLike: TypeAlias = tf.Tensor | tf.RaggedTensor
19-
_RaggedTensorLikeT = TypeVar("_RaggedTensorLikeT", tf.Tensor, tf.RaggedTensor)
17+
# _SparseTensorLike: TypeAlias = tf.Tensor | tf.SparseTensor
18+
# _RaggedTensorLike: TypeAlias = tf.Tensor | tf.RaggedTensor
19+
# _RaggedTensorLikeT = TypeVar("_RaggedTensorLikeT", tf.Tensor, tf.RaggedTensor)
2020
_Gradients: TypeAlias = tf.Tensor | tf.IndexedSlices
2121

2222
class _KerasSerializable1(Protocol):
@@ -27,6 +27,7 @@ class _KerasSerializable2(Protocol):
2727

2828
_KerasSerializable: TypeAlias = _KerasSerializable1 | _KerasSerializable2
2929

30+
_Slice: TypeAlias = int | slice | None
3031
_FloatDataSequence: TypeAlias = Sequence[float] | Sequence[_FloatDataSequence]
3132
_StrDataSequence: TypeAlias = Sequence[str] | Sequence[_StrDataSequence]
3233
_ScalarTensorCompatible: TypeAlias = tf.Tensor | str | float | np.ndarray[Any, Any] | np.number[Any]

0 commit comments

Comments
 (0)