Skip to content

Commit f6ccdab

Browse files
committed
fix: add missing imports, re-exports, return values
Also a few type fixes
1 parent 9c02549 commit f6ccdab

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

stubs/tensorflow/tensorflow/__init__.pyi

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ from typing_extensions import Self
1212
from google.protobuf.message import Message
1313
from tensorflow import (
1414
data as data,
15+
debugging as debugging,
1516
experimental as experimental,
1617
feature_column as feature_column,
18+
image as image,
1719
initializers as initializers,
1820
io as io,
1921
keras as keras,
@@ -26,13 +28,15 @@ from tensorflow._aliases import (
2628
AnyArray,
2729
DTypeLike,
2830
IntArray,
31+
IntTensorCompatible,
2932
RaggedTensorLike,
3033
ScalarTensorCompatible,
3134
ShapeLike,
3235
Signature,
3336
Slice,
3437
SparseTensorCompatible,
3538
TensorCompatible,
39+
TensorLike,
3640
UIntTensorCompatible,
3741
)
3842
from tensorflow.autodiff import GradientTape as GradientTape
@@ -448,17 +452,35 @@ def ones_like(
448452

449453
def reshape(tensor: TensorCompatible, shape: ShapeLike | Tensor, name: str | None = None) -> Tensor: ...
450454
def reverse(tensor: TensorCompatible, axis: IntTensorCompatible, name: str | None = None) -> Tensor: ...
455+
456+
_ElemT = TypeVar("_ElemT", bound=TensorLike)
457+
_RetT = TypeVar("_RetT", bound=TensorLike)
458+
459+
@overload
451460
def map_fn(
452-
fn: Callable[TensorLike | TensorCompatible, TensorLike],
453-
elems: TensorLike | TensorCompatible,
461+
fn: Callable[[_ElemT], _RetT],
462+
elems: _ElemT,
454463
dtype: DTypeLike | None = None,
455464
parallel_iterations: int | None = None,
456-
back_prop: bool = True,
457-
swap_memory: bool = False,
458-
infer_shape: bool = True,
465+
back_prop: _bool = True,
466+
swap_memory: _bool = False,
467+
infer_shape: _bool = True,
459468
name: str | None = None,
460-
fn_output_signature: Signature = None,
461-
) -> Tensor: ...
469+
fn_output_signature: Signature | None = None,
470+
) -> _RetT: ...
471+
@overload
472+
def map_fn(
473+
fn: Callable[[Tensor], _RetT],
474+
elems: TensorCompatible,
475+
dtype: DTypeLike | None = None,
476+
parallel_iterations: int | None = None,
477+
back_prop: _bool = True,
478+
swap_memory: _bool = False,
479+
infer_shape: _bool = True,
480+
name: str | None = None,
481+
fn_output_signature: Signature | None = None,
482+
) -> _RetT: ...
483+
462484
def pad(
463485
tensor: TensorCompatible,
464486
paddings: Tensor | IntArray | Iterable[Iterable[int]],

stubs/tensorflow/tensorflow/_aliases.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TensorOrArray: TypeAlias = tf.Tensor | AnyArray
5757

5858
ShapeLike: TypeAlias = tf.TensorShape | Iterable[ScalarTensorCompatible | None] | int | tf.Tensor
5959
DTypeLike: TypeAlias = DType | str | np.dtype[Any] | int
60-
Signature: DType | tf.RaggedTensorSpec | tf.SparseTensorSpec | Sequence[Signature]
60+
Signature: TypeAlias = DType | tf.RaggedTensorSpec | tf.SparseTensorSpec | Sequence[Signature]
6161

6262
ContainerTensors: TypeAlias = ContainerGeneric[tf.Tensor]
6363
ContainerTensorsLike: TypeAlias = ContainerGeneric[TensorLike]

stubs/tensorflow/tensorflow/debugging.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ def assert_greater_equal(
66
message: str | None = None,
77
summarize: int | None = None,
88
name: str | None = None,
9-
): ...
9+
) -> None: ...
1010
def __getattr__(name: str): ... # incomplete module
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import tensorflow as tf
12
from tensorflow._aliases import IntTensorCompatible, TensorCompatible
23

3-
def random_crop(value: TensorCompatible, size: IntTensorCompatible, seed: int | None = None, name: str | None = None): ...
4+
def random_crop(
5+
value: TensorCompatible, size: IntTensorCompatible, seed: int | None = None, name: str | None = None
6+
) -> tf.Tensor: ...
47
def __getattr__(name: str): ... # incomplete module

0 commit comments

Comments
 (0)