Remove pytype workarounds from third-party stubs (#14471)

This commit is contained in:
Sebastian Rittau
2025-07-27 13:05:57 +02:00
committed by GitHub
parent 7e16c80989
commit 981bd8eb8d
6 changed files with 10 additions and 17 deletions
@@ -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: ...
@@ -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 *
-1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -2
View File
@@ -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]
+7 -10
View File
@@ -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