From 981bd8eb8d37381fa692f447fa8540ca4dd226a9 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 27 Jul 2025 13:05:57 +0200 Subject: [PATCH] Remove pytype workarounds from third-party stubs (#14471) --- .../templatetags/import_export_tags.pyi | 2 +- stubs/networkx/networkx/utils/__init__.pyi | 2 -- stubs/seaborn/seaborn/_core/groupby.pyi | 1 - stubs/seaborn/seaborn/_stats/aggregation.pyi | 2 +- stubs/tensorflow/tensorflow/_aliases.pyi | 3 +-- stubs/tensorflow/tensorflow/io/__init__.pyi | 17 +++++++---------- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/stubs/django-import-export/import_export/templatetags/import_export_tags.pyi b/stubs/django-import-export/import_export/templatetags/import_export_tags.pyi index dcbfa25a6..9d6c0e4d7 100644 --- a/stubs/django-import-export/import_export/templatetags/import_export_tags.pyi +++ b/stubs/django-import-export/import_export/templatetags/import_export_tags.pyi @@ -4,5 +4,5 @@ from django.template import Library register: Library -# @register.simple_tag # commented out for pytype +@register.simple_tag def compare_values(value1: str, value2: str) -> LiteralString: ... diff --git a/stubs/networkx/networkx/utils/__init__.pyi b/stubs/networkx/networkx/utils/__init__.pyi index 960b428e6..c615a6e8a 100644 --- a/stubs/networkx/networkx/utils/__init__.pyi +++ b/stubs/networkx/networkx/utils/__init__.pyi @@ -1,11 +1,9 @@ from networkx.utils.backends import * -from networkx.utils.backends import _dispatchable as _dispatchable # for pytype to see the re-export in networkx/__init__.py from networkx.utils.configs import * from networkx.utils.configs import NetworkXConfig from networkx.utils.decorators import * from networkx.utils.heaps import * from networkx.utils.misc import * -from networkx.utils.misc import _clear_cache as _clear_cache # for pytype to see the re-export in networkx/__init__.py from networkx.utils.random_sequence import * from networkx.utils.rcm import * from networkx.utils.union_find import * diff --git a/stubs/seaborn/seaborn/_core/groupby.pyi b/stubs/seaborn/seaborn/_core/groupby.pyi index e4100d0d8..f466aee67 100644 --- a/stubs/seaborn/seaborn/_core/groupby.pyi +++ b/stubs/seaborn/seaborn/_core/groupby.pyi @@ -7,7 +7,6 @@ from pandas import DataFrame # pandas._typing.AggFuncTypeFrame is partially Unknown _AggFuncTypeBase: TypeAlias = Callable[..., Incomplete] | str | ufunc -# Using Hashable instead of HashableT to work around pytype issue _AggFuncTypeDictFrame: TypeAlias = Mapping[Hashable, _AggFuncTypeBase | list[_AggFuncTypeBase]] _AggFuncTypeFrame: TypeAlias = _AggFuncTypeBase | list[_AggFuncTypeBase] | _AggFuncTypeDictFrame diff --git a/stubs/seaborn/seaborn/_stats/aggregation.pyi b/stubs/seaborn/seaborn/_stats/aggregation.pyi index d14b8e673..cf30b12a2 100644 --- a/stubs/seaborn/seaborn/_stats/aggregation.pyi +++ b/stubs/seaborn/seaborn/_stats/aggregation.pyi @@ -11,7 +11,7 @@ class Agg(Stat): @dataclass class Est(Stat): func: str | Callable[[Vector], float] = "mean" - errorbar: str | tuple[str, float] = ... # ("ci", 95) # pytype parse error + errorbar: str | tuple[str, float] = ("ci", 95) n_boot: int = 1000 seed: int | None = None diff --git a/stubs/tensorflow/tensorflow/_aliases.pyi b/stubs/tensorflow/tensorflow/_aliases.pyi index d8beae33e..6bc6918a6 100644 --- a/stubs/tensorflow/tensorflow/_aliases.pyi +++ b/stubs/tensorflow/tensorflow/_aliases.pyi @@ -5,7 +5,6 @@ from collections.abc import Iterable, Mapping, Sequence from typing import Any, Protocol, TypeVar from typing_extensions import TypeAlias -import numpy # pytype needs the unaliased import to resolve DTypeLike import numpy as np import numpy.typing as npt import tensorflow as tf @@ -55,7 +54,7 @@ SparseTensorCompatible: TypeAlias = TensorCompatible | tf.SparseTensor TensorOrArray: TypeAlias = tf.Tensor | AnyArray ShapeLike: TypeAlias = tf.TensorShape | Iterable[ScalarTensorCompatible | None] | int | tf.Tensor -DTypeLike: TypeAlias = DType | str | numpy.dtype[Any] | int +DTypeLike: TypeAlias = DType | str | np.dtype[Any] | int ContainerTensors: TypeAlias = ContainerGeneric[tf.Tensor] ContainerTensorsLike: TypeAlias = ContainerGeneric[TensorLike] diff --git a/stubs/tensorflow/tensorflow/io/__init__.pyi b/stubs/tensorflow/tensorflow/io/__init__.pyi index 4f7a2f795..51f45b5fd 100644 --- a/stubs/tensorflow/tensorflow/io/__init__.pyi +++ b/stubs/tensorflow/tensorflow/io/__init__.pyi @@ -48,19 +48,16 @@ class TFRecordWriter: self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... -# Also defaults are missing here because pytype crashes when a default is present reported -# in this [issue](https://github.com/google/pytype/issues/1410#issue-1669793588). After -# next release the defaults can be added back. class FixedLenFeature(NamedTuple): shape: ShapeLike dtype: DTypeLike - default_value: TensorCompatible | None = ... + default_value: TensorCompatible | None = None class FixedLenSequenceFeature(NamedTuple): shape: ShapeLike dtype: DTypeLike - allow_missing: bool = ... - default_value: TensorCompatible | None = ... + allow_missing: bool = False + default_value: TensorCompatible | None = None class VarLenFeature(NamedTuple): dtype: DTypeLike @@ -70,7 +67,7 @@ class SparseFeature(NamedTuple): value_key: str dtype: DTypeLike size: int | list[int] - already_sorted: bool = ... + already_sorted: bool = False class RaggedFeature(NamedTuple): # Mypy doesn't support nested NamedTuples, but at runtime they actually do use @@ -94,12 +91,12 @@ class RaggedFeature(NamedTuple): length: int dtype: DTypeLike - value_key: str | None = ... + value_key: str | None = None partitions: tuple[ # type: ignore[name-defined] RowSplits | RowLengths | RowStarts | RowLimits | ValueRowIds | UniformRowLength, ... - ] = ... + ] = () row_splits_dtype: DTypeLike = ... - validate: bool = ... + validate: bool = False def parse_example( serialized: TensorCompatible, features: _FeatureSpecs, example_names: Iterable[str] | None = None, name: str | None = None