Replace Incomplete | None = None in third party stubs (#14063)

This commit is contained in:
Sebastian Rittau
2025-05-15 21:37:43 +02:00
committed by GitHub
parent acc51542c9
commit 126768408a
488 changed files with 2259 additions and 4044 deletions
+2 -2
View File
@@ -161,7 +161,7 @@ class Variable(Tensor, metaclass=_VariableMetaclass):
name: str | None = None,
# Real type is VariableDef protobuf type. Can be added after adding script
# to generate tensorflow protobuf stubs with mypy-protobuf.
variable_def: Incomplete | None = None,
variable_def=None,
dtype: DTypeLike | None = None,
import_scope: str | None = None,
constraint: Callable[[Tensor], Tensor] | None = None,
@@ -203,7 +203,7 @@ class Operation:
control_inputs: Iterable[Tensor | Operation] | None = None,
input_types: Iterable[DType] | None = None,
original_op: Operation | None = None,
op_def: Incomplete | None = None,
op_def=None,
) -> None: ...
@property
def inputs(self) -> list[Tensor]: ...
@@ -187,7 +187,7 @@ class Dataset(ABC, Generic[_T1_co]):
path: str,
compression: _CompressionTypes = None,
shard_func: Callable[[_T1_co], int] | None = None,
checkpoint_args: Incomplete | None = None,
checkpoint_args=None,
) -> None: ...
def scan(
self, initial_state: _T2, scan_func: Callable[[_T2, _T1_co], tuple[_T2, _T3]], name: str | None = None
+17 -49
View File
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from abc import ABC, abstractmethod
from collections.abc import Callable
from typing import Any, Final, Literal, TypeVar, overload
@@ -14,9 +13,7 @@ from tensorflow.keras.metrics import (
class Loss(ABC):
reduction: _ReductionValues
name: str | None
def __init__(
self, name: str | None = None, reduction: _ReductionValues = "sum_over_batch_size", dtype: Incomplete | None = None
) -> None: ...
def __init__(self, name: str | None = None, reduction: _ReductionValues = "sum_over_batch_size", dtype=None) -> None: ...
@abstractmethod
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
@classmethod
@@ -34,7 +31,7 @@ class BinaryCrossentropy(Loss):
axis: int = -1,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "binary_crossentropy",
dtype: Incomplete | None = None,
dtype=None,
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
@@ -49,7 +46,7 @@ class BinaryFocalCrossentropy(Loss):
axis: int = -1,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "binary_focal_crossentropy",
dtype: Incomplete | None = None,
dtype=None,
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
@@ -61,16 +58,13 @@ class CategoricalCrossentropy(Loss):
axis: int = -1,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "categorical_crossentropy",
dtype: Incomplete | None = None,
dtype=None,
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class CategoricalHinge(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "categorical_hinge",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "categorical_hinge", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
@@ -80,81 +74,58 @@ class CosineSimilarity(Loss):
axis: int = -1,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "cosine_similarity",
dtype: Incomplete | None = None,
dtype=None,
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class Hinge(Loss):
def __init__(
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "hinge", dtype: Incomplete | None = None
) -> None: ...
def __init__(self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "hinge", dtype=None) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class Huber(Loss):
def __init__(
self,
delta: float = 1.0,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "huber_loss",
dtype: Incomplete | None = None,
self, delta: float = 1.0, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "huber_loss", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class KLDivergence(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "kl_divergence",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "kl_divergence", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class LogCosh(Loss):
def __init__(
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "log_cosh", dtype: Incomplete | None = None
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "log_cosh", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class MeanAbsoluteError(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "mean_absolute_error",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "mean_absolute_error", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class MeanAbsolutePercentageError(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "mean_absolute_percentage_error",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "mean_absolute_percentage_error", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class MeanSquaredError(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "mean_squared_error",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "mean_squared_error", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class MeanSquaredLogarithmicError(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "mean_squared_logarithmic_error",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "mean_squared_logarithmic_error", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class Poisson(Loss):
def __init__(
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "poisson", dtype: Incomplete | None = None
) -> None: ...
def __init__(self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "poisson", dtype=None) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class SparseCategoricalCrossentropy(Loss):
@@ -164,16 +135,13 @@ class SparseCategoricalCrossentropy(Loss):
ignore_class: int | None = None,
reduction: _ReductionValues = "sum_over_batch_size",
name: str = "sparse_categorical_crossentropy",
dtype: Incomplete | None = None,
dtype=None,
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
class SquaredHinge(Loss):
def __init__(
self,
reduction: _ReductionValues = "sum_over_batch_size",
name: str | None = "squared_hinge",
dtype: Incomplete | None = None,
self, reduction: _ReductionValues = "sum_over_batch_size", name: str | None = "squared_hinge", dtype=None
) -> None: ...
def call(self, y_true: Tensor, y_pred: Tensor) -> Tensor: ...
+4 -6
View File
@@ -22,9 +22,7 @@ class Model(Layer[_InputT_contra, _OutputT_co]):
optimizer: Optimizer | None
# This is actually TensorFlowTrainer.loss
@deprecated("Instead, use `model.compute_loss(x, y, y_pred, sample_weight)`.")
def loss(
self, y: TensorCompatible | None, y_pred: TensorCompatible | None, sample_weight: Incomplete | None = None
) -> tf.Tensor | None: ...
def loss(self, y: TensorCompatible | None, y_pred: TensorCompatible | None, sample_weight=None) -> tf.Tensor | None: ...
stop_training: bool
def __new__(cls, *args: Any, **kwargs: Any) -> Model[_InputT_contra, _OutputT_co]: ...
@@ -67,11 +65,11 @@ class Model(Layer[_InputT_contra, _OutputT_co]):
x: TensorCompatible | None = None,
y: TensorCompatible | None = None,
y_pred: TensorCompatible | None = None,
sample_weight: Incomplete | None = None,
sample_weight=None,
training: bool = True,
) -> tf.Tensor | None: ...
def compute_metrics(
self, x: TensorCompatible, y: TensorCompatible, y_pred: TensorCompatible, sample_weight: Incomplete | None = None
self, x: TensorCompatible, y: TensorCompatible, y_pred: TensorCompatible, sample_weight=None
) -> dict[str, float]: ...
def get_metrics_result(self) -> dict[str, float]: ...
def make_train_function(self, force: bool = False) -> Callable[[tf.data.Iterator[Incomplete]], dict[str, float]]: ...
@@ -146,7 +144,7 @@ class Model(Layer[_InputT_contra, _OutputT_co]):
def load_weights(self, filepath: str | Path, skip_mismatch: bool = False, *, by_name: bool = False) -> None: ...
def get_config(self) -> dict[str, Any]: ...
@classmethod
def from_config(cls, config: dict[str, Any], custom_objects: Incomplete | None = None) -> Self: ...
def from_config(cls, config: dict[str, Any], custom_objects=None) -> Self: ...
def to_json(self, **kwargs: Any) -> str: ...
@property
def weights(self) -> list[Variable]: ...
@@ -71,8 +71,8 @@ class SaveOptions:
experimental_custom_gradients: bool = True,
experimental_image_format: bool = False,
experimental_skip_saver: bool = False,
experimental_sharding_callback: Incomplete | None = None,
extra_tags: Incomplete | None = None,
experimental_sharding_callback=None,
extra_tags=None,
) -> None: ...
def contains_saved_model(export_dir: str | Path) -> bool: ...
+1 -4
View File
@@ -1,5 +1,4 @@
import abc
from _typeshed import Incomplete
from collections.abc import Callable, Generator
from contextlib import AbstractContextManager, contextmanager
from typing import Literal
@@ -56,6 +55,4 @@ def text(name: str, data: str | tf.Tensor, step: int | tf.Tensor | None = None,
def trace_export(name: str, step: int | tf.Tensor | None = None, profiler_outdir: str | None = None) -> None: ...
def trace_off() -> None: ...
def trace_on(graph: bool = True, profiler: bool = False, profiler_outdir: str | None = None) -> None: ...
def write(
tag: str, tensor: tf.Tensor, step: int | tf.Tensor | None = None, metadata: Incomplete | None = None, name: str | None = None
) -> bool: ...
def write(tag: str, tensor: tf.Tensor, step: int | tf.Tensor | None = None, metadata=None, name: str | None = None) -> bool: ...
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from collections.abc import Callable
from typing import Any, TypeVar
from typing_extensions import Self
@@ -31,7 +30,7 @@ class CheckpointOptions:
experimental_write_callbacks: None | list[Callable[[str], object] | Callable[[], object]] = None,
enable_async: bool = False,
experimental_skip_slot_variables: bool = False,
experimental_sharding_callback: Incomplete | None = None,
experimental_sharding_callback=None,
) -> None: ...
_T = TypeVar("_T", bound=list[str] | tuple[str] | dict[int, str])