Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubgen: Replace obsolete typing aliases with builtin containers #16780

Merged
merged 3 commits into from
Feb 18, 2024

Conversation

hamdanal
Copy link
Collaborator

Addresses part of #16737

This only replaces typing symbols that have equivalents in the builtins module. Replacing other symbols, like those from the collections.abc module, are a bit more complicated so I suggest we handle them separately.

I also changed the default TypedDict module from typing_extensions to typing as typeshed dropped support for Python 3.7.

@hamdanal
Copy link
Collaborator Author

hamdanal commented Jan 13, 2024

If you are interested in some primer diff, I ran the change on these packages:

matplotlib==3.7.1
numpy==1.24.3
pandas==2.0.2
scipy==1.10.1
seaborn==0.13.1
Click to expand

diff --git a/out/upstream/numpy/numpy/array_api/_array_object.pyi b/out/local/numpy/numpy/array_api/_array_object.pyi
index b0cea439b..cbe47f550 100644
--- a/out/upstream/numpy/numpy/array_api/_array_object.pyi
+++ b/out/local/numpy/numpy/array_api/_array_object.pyi
@@ -8 +7,0 @@ from numpy import array_api as array_api
-from typing import Tuple
@@ -19 +18 @@ class Array:
-    def __dlpack_device__(self) -> Tuple[IntEnum, int]: ...
+    def __dlpack_device__(self) -> tuple[IntEnum, int]: ...
@@ -24 +23 @@ class Array:
-    def __getitem__(self, key: int | slice | ellipsis | Tuple[int | slice | ellipsis, ...] | Array) -> Array: ...
+    def __getitem__(self, key: int | slice | ellipsis | tuple[int | slice | ellipsis, ...] | Array) -> Array: ...
@@ -41 +40 @@ class Array:
-    def __setitem__(self, key: int | slice | ellipsis | Tuple[int | slice | ellipsis, ...] | Array, value: int | float | bool | Array) -> None: ...
+    def __setitem__(self, key: int | slice | ellipsis | tuple[int | slice | ellipsis, ...] | Array, value: int | float | bool | Array) -> None: ...
@@ -81 +80 @@ class Array:
-    def shape(self) -> Tuple[int, ...]: ...
+    def shape(self) -> tuple[int, ...]: ...
diff --git a/out/upstream/numpy/numpy/array_api/_creation_functions.pyi b/out/local/numpy/numpy/array_api/_creation_functions.pyi
index b500d9f3e..25dfab7cd 100644
--- a/out/upstream/numpy/numpy/array_api/_creation_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_creation_functions.pyi
@@ -4 +3,0 @@ from collections.abc import Sequence as Sequence
-from typing import List, Tuple
@@ -8 +7 @@ def arange(start: int | float, stop: int | float | None = None, step: int | floa
-def empty(shape: int | Tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
+def empty(shape: int | tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
@@ -12 +11 @@ def from_dlpack(x: object) -> Array: ...
-def full(shape: int | Tuple[int, ...], fill_value: int | float, *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
+def full(shape: int | tuple[int, ...], fill_value: int | float, *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
@@ -15,2 +14,2 @@ def linspace(start: int | float, stop: int | float, num: int, *, dtype: Dtype |
-def meshgrid(*arrays: Array, indexing: str = 'xy') -> List[Array]: ...
-def ones(shape: int | Tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
+def meshgrid(*arrays: Array, indexing: str = 'xy') -> list[Array]: ...
+def ones(shape: int | tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
@@ -20 +19 @@ def triu(x: Array, *, k: int = 0) -> Array: ...
-def zeros(shape: int | Tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
+def zeros(shape: int | tuple[int, ...], *, dtype: Dtype | None = None, device: Device | None = None) -> Array: ...
diff --git a/out/upstream/numpy/numpy/array_api/_data_type_functions.pyi b/out/local/numpy/numpy/array_api/_data_type_functions.pyi
index a67ad9cdd..abc966440 100644
--- a/out/upstream/numpy/numpy/array_api/_data_type_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_data_type_functions.pyi
@@ -5 +4,0 @@ from dataclasses import dataclass
-from typing import List, Tuple
@@ -8,2 +7,2 @@ def astype(x: Array, dtype: Dtype, *, copy: bool = True) -> Array: ...
-def broadcast_arrays(*arrays: Array) -> List[Array]: ...
-def broadcast_to(x: Array, shape: Tuple[int, ...]) -> Array: ...
+def broadcast_arrays(*arrays: Array) -> list[Array]: ...
+def broadcast_to(x: Array, shape: tuple[int, ...]) -> Array: ...
diff --git a/out/upstream/numpy/numpy/array_api/_manipulation_functions.pyi b/out/local/numpy/numpy/array_api/_manipulation_functions.pyi
index baa5a6962..835eb1f4f 100644
--- a/out/upstream/numpy/numpy/array_api/_manipulation_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_manipulation_functions.pyi
@@ -3 +2,0 @@ from ._data_type_functions import result_type as result_type
-from typing import List, Tuple
@@ -5 +4 @@ from typing import List, Tuple
-def concat(arrays: Tuple[Array, ...] | List[Array], *, axis: int | None = 0) -> Array: ...
+def concat(arrays: tuple[Array, ...] | list[Array], *, axis: int | None = 0) -> Array: ...
@@ -7,6 +6,6 @@ def expand_dims(x: Array, *, axis: int) -> Array: ...
-def flip(x: Array, *, axis: int | Tuple[int, ...] | None = None) -> Array: ...
-def permute_dims(x: Array, axes: Tuple[int, ...]) -> Array: ...
-def reshape(x: Array, shape: Tuple[int, ...]) -> Array: ...
-def roll(x: Array, shift: int | Tuple[int, ...], *, axis: int | Tuple[int, ...] | None = None) -> Array: ...
-def squeeze(x: Array, axis: int | Tuple[int, ...]) -> Array: ...
-def stack(arrays: Tuple[Array, ...] | List[Array], *, axis: int = 0) -> Array: ...
+def flip(x: Array, *, axis: int | tuple[int, ...] | None = None) -> Array: ...
+def permute_dims(x: Array, axes: tuple[int, ...]) -> Array: ...
+def reshape(x: Array, shape: tuple[int, ...]) -> Array: ...
+def roll(x: Array, shift: int | tuple[int, ...], *, axis: int | tuple[int, ...] | None = None) -> Array: ...
+def squeeze(x: Array, axis: int | tuple[int, ...]) -> Array: ...
+def stack(arrays: tuple[Array, ...] | list[Array], *, axis: int = 0) -> Array: ...
diff --git a/out/upstream/numpy/numpy/array_api/_searching_functions.pyi b/out/local/numpy/numpy/array_api/_searching_functions.pyi
index 5a5c4010f..eae998da1 100644
--- a/out/upstream/numpy/numpy/array_api/_searching_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_searching_functions.pyi
@@ -2 +1,0 @@ from ._array_object import Array as Array
-from typing import Tuple
@@ -6 +5 @@ def argmin(x: Array, *, axis: int | None = None, keepdims: bool = False) -> Arra
-def nonzero(x: Array) -> Tuple[Array, ...]: ...
+def nonzero(x: Array) -> tuple[Array, ...]: ...
diff --git a/out/upstream/numpy/numpy/array_api/_statistical_functions.pyi b/out/local/numpy/numpy/array_api/_statistical_functions.pyi
index 0a5189f24..60e4b1f88 100644
--- a/out/upstream/numpy/numpy/array_api/_statistical_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_statistical_functions.pyi
@@ -5 +4,0 @@ from ._typing import Dtype as Dtype
-from typing import Tuple
@@ -7,7 +6,7 @@ from typing import Tuple
-def max(x: Array, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
-def mean(x: Array, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
-def min(x: Array, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
-def prod(x: Array, *, axis: int | Tuple[int, ...] | None = None, dtype: Dtype | None = None, keepdims: bool = False) -> Array: ...
-def std(x: Array, *, axis: int | Tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) -> Array: ...
-def sum(x: Array, *, axis: int | Tuple[int, ...] | None = None, dtype: Dtype | None = None, keepdims: bool = False) -> Array: ...
-def var(x: Array, *, axis: int | Tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) -> Array: ...
+def max(x: Array, *, axis: int | tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
+def mean(x: Array, *, axis: int | tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
+def min(x: Array, *, axis: int | tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
+def prod(x: Array, *, axis: int | tuple[int, ...] | None = None, dtype: Dtype | None = None, keepdims: bool = False) -> Array: ...
+def std(x: Array, *, axis: int | tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) -> Array: ...
+def sum(x: Array, *, axis: int | tuple[int, ...] | None = None, dtype: Dtype | None = None, keepdims: bool = False) -> Array: ...
+def var(x: Array, *, axis: int | tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) -> Array: ...
diff --git a/out/upstream/numpy/numpy/array_api/_utility_functions.pyi b/out/local/numpy/numpy/array_api/_utility_functions.pyi
index 88b3b64da..9ac842412 100644
--- a/out/upstream/numpy/numpy/array_api/_utility_functions.pyi
+++ b/out/local/numpy/numpy/array_api/_utility_functions.pyi
@@ -2 +1,0 @@ from ._array_object import Array as Array
-from typing import Tuple
@@ -4,2 +3,2 @@ from typing import Tuple
-def all(x: Array, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
-def any(x: Array, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
+def all(x: Array, *, axis: int | tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
+def any(x: Array, *, axis: int | tuple[int, ...] | None = None, keepdims: bool = False) -> Array: ...
diff --git a/out/upstream/pandas/pandas/_typing.pyi b/out/local/pandas/pandas/_typing.pyi
index b82dddee2..76a1a992e 100644
--- a/out/upstream/pandas/pandas/_typing.pyi
+++ b/out/local/pandas/pandas/_typing.pyi
@@ -19 +19 @@ from pandas.io.formats.format import EngFormatter as EngFormatter
-from typing import Any, Callable, Dict, Hashable, Iterator, List, Mapping, Protocol, Sequence, Tuple, Type as type_t, TypeVar
+from typing import Any, Callable, Hashable, Iterator, Mapping, Protocol, Sequence, TypeVar
@@ -42,2 +42,2 @@ Level = Hashable
-Shape = Tuple[int, ...]
-Suffixes = Tuple[str | None, str | None]
+Shape = tuple[int, ...]
+Suffixes = tuple[str | None, str | None]
@@ -45 +45 @@ Ordered = bool | None
-JSONSerializable = PythonScalar | List | Dict | None
+JSONSerializable = PythonScalar | list | dict | None
@@ -47 +47 @@ Frequency: Incomplete
-Axes = AnyArrayLike | List | range
+Axes = AnyArrayLike | list | range
@@ -49 +49 @@ RandomState: Incomplete
-NpDtype = str | np.dtype | type_t[str | complex | bool | object]
+NpDtype = str | np.dtype | type[str | complex | bool | object]
@@ -52 +52 @@ AstypeArg: Incomplete
-DtypeArg = Dtype | Dict[Hashable, Dtype]
+DtypeArg = Dtype | dict[Hashable, Dtype]
@@ -54,2 +54,2 @@ DtypeObj: Incomplete
-ConvertersArg = Dict[Hashable, Callable[[Dtype], Dtype]]
-ParseDatesArg = bool | List[Hashable] | List[List[Hashable]] | Dict[Hashable, List[Hashable]]
+ConvertersArg = dict[Hashable, Callable[[Dtype], Dtype]]
+ParseDatesArg = bool | list[Hashable] | list[list[Hashable]] | dict[Hashable, list[Hashable]]
@@ -63,2 +63,2 @@ AggFuncTypeBase = Callable | str
-AggFuncTypeDict = Dict[Hashable, AggFuncTypeBase | List[AggFuncTypeBase]]
-AggFuncType = AggFuncTypeBase | List[AggFuncTypeBase] | AggFuncTypeDict
+AggFuncTypeDict = dict[Hashable, AggFuncTypeBase | list[AggFuncTypeBase]]
+AggFuncType = AggFuncTypeBase | list[AggFuncTypeBase] | AggFuncTypeDict
@@ -98,2 +98,2 @@ FilePath: Incomplete
-StorageOptions = Dict[str, Any] | None
-CompressionDict = Dict[str, Any]
+StorageOptions = dict[str, Any] | None
+CompressionDict = dict[str, Any]
@@ -101 +101 @@ CompressionOptions: Incomplete
-FormattersType = List[Callable] | Tuple[Callable, ...] | Mapping[str | int, Callable]
+FormattersType = list[Callable] | tuple[Callable, ...] | Mapping[str | int, Callable]
@@ -110 +110 @@ ScalarIndexer = int | np.integer
-SequenceIndexer = slice | List[int] | np.ndarray
+SequenceIndexer = slice | list[int] | np.ndarray
@@ -112 +112 @@ PositionalIndexer = ScalarIndexer | SequenceIndexer
-PositionalIndexerTuple = Tuple[PositionalIndexer, PositionalIndexer]
+PositionalIndexerTuple = tuple[PositionalIndexer, PositionalIndexer]
diff --git a/out/upstream/pandas/pandas/core/apply.pyi b/out/local/pandas/pandas/core/apply.pyi
index 2f6c45698..c2a37f47b 100644
--- a/out/upstream/pandas/pandas/core/apply.pyi
+++ b/out/local/pandas/pandas/core/apply.pyi
@@ -20 +20 @@ from pandas.util._decorators import cache_readonly as cache_readonly
-from typing import Any, Callable, Dict, Hashable, Iterable, Iterator
+from typing import Any, Callable, Hashable, Iterable, Iterator
@@ -22 +22 @@ from typing import Any, Callable, Dict, Hashable, Iterable, Iterator
-ResType = Dict[int, Any]
+ResType = dict[int, Any]
diff --git a/out/upstream/pandas/pandas/core/tools/datetimes.pyi b/out/local/pandas/pandas/core/tools/datetimes.pyi
index b0c228948..438c71d84 100644
--- a/out/upstream/pandas/pandas/core/tools/datetimes.pyi
+++ b/out/local/pandas/pandas/core/tools/datetimes.pyi
@@ -8 +8 @@ from pandas.core.indexes.datetimes import DatetimeIndex
-from typing import List, Tuple, TypedDict, overload
+from typing import TypedDict, overload
@@ -12 +12 @@ __all__ = ['DateParseError', 'should_cache', 'to_datetime']
-ArrayConvertible = List | Tuple | AnyArrayLike
+ArrayConvertible = list | tuple | AnyArrayLike
@@ -16 +16 @@ DatetimeScalarOrArrayConvertible = DatetimeScalar | ArrayConvertible
-DatetimeDictArg = List[Scalar] | Tuple[Scalar, ...] | AnyArrayLike
+DatetimeDictArg = list[Scalar] | tuple[Scalar, ...] | AnyArrayLike
diff --git a/out/upstream/pandas/pandas/io/formats/printing.pyi b/out/local/pandas/pandas/io/formats/printing.pyi
index 0fb935574..7f4fa043d 100644
--- a/out/upstream/pandas/pandas/io/formats/printing.pyi
+++ b/out/local/pandas/pandas/io/formats/printing.pyi
@@ -3 +3 @@ from pandas.core.dtypes.inference import is_sequence as is_sequence
-from typing import Any, Callable, Dict, Iterable, Mapping
+from typing import Any, Callable, Iterable, Mapping
@@ -15 +15 @@ def format_object_summary(obj, formatter: Callable, is_justify: bool = True, nam
-class PrettyDict(Dict[_KT, _VT]): ...
+class PrettyDict(dict[_KT, _VT]): ...
diff --git a/out/upstream/pandas/pandas/io/formats/style_render.pyi b/out/local/pandas/pandas/io/formats/style_render.pyi
index 92471507c..adc2421cb 100644
--- a/out/upstream/pandas/pandas/io/formats/style_render.pyi
+++ b/out/local/pandas/pandas/io/formats/style_render.pyi
@@ -10 +10 @@ from pandas.core.dtypes.generic import ABCSeries as ABCSeries
-from typing import Any, Callable, Dict, List, Sequence, Tuple, TypedDict
+from typing import Any, Callable, Sequence, TypedDict
@@ -14,3 +14,3 @@ BaseFormatter = str | Callable
-ExtFormatter = BaseFormatter | Dict[Any, BaseFormatter | None]
-CSSPair = Tuple[str, str | float]
-CSSList = List[CSSPair]
+ExtFormatter = BaseFormatter | dict[Any, BaseFormatter | None]
+CSSPair = tuple[str, str | float]
+CSSList = list[CSSPair]
@@ -22 +22 @@ class CSSDict(TypedDict):
-CSSStyles = List[CSSDict]
+CSSStyles = list[CSSDict]
diff --git a/out/upstream/pandas/pandas/util/version/__init__.pyi b/out/local/pandas/pandas/util/version/__init__.pyi
index 464a0d43b..2b12718c6 100644
--- a/out/upstream/pandas/pandas/util/version/__init__.pyi
+++ b/out/local/pandas/pandas/util/version/__init__.pyi
@@ -2 +2 @@ from _typeshed import Incomplete
-from typing import Callable, NamedTuple, Tuple
+from typing import Callable, NamedTuple
@@ -26 +26 @@ InfiniteTypes = InfinityType | NegativeInfinityType
-PrePostDevType = InfiniteTypes | Tuple[str, int]
+PrePostDevType = InfiniteTypes | tuple[str, int]
@@ -28,3 +28,3 @@ SubLocalType = InfiniteTypes | int | str
-LocalType = NegativeInfinityType | Tuple[SubLocalType | Tuple[SubLocalType, str] | Tuple[NegativeInfinityType, SubLocalType], ...]
-CmpKey = Tuple[int, Tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType]
-LegacyCmpKey = Tuple[int, Tuple[str, ...]]
+LocalType = NegativeInfinityType | tuple[SubLocalType | tuple[SubLocalType, str] | tuple[NegativeInfinityType, SubLocalType], ...]
+CmpKey = tuple[int, tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType]
+LegacyCmpKey = tuple[int, tuple[str, ...]]
diff --git a/out/upstream/scipy/scipy/integrate/_quadrature.pyi b/out/local/scipy/scipy/integrate/_quadrature.pyi
index fbd6148a3..1369d6042 100644
--- a/out/upstream/scipy/scipy/integrate/_quadrature.pyi
+++ b/out/local/scipy/scipy/integrate/_quadrature.pyi
@@ -2 +2 @@ from _typeshed import Incomplete
-from typing import Any, Dict, NamedTuple, Protocol, Tuple
+from typing import Any, NamedTuple, Protocol
@@ -12 +12 @@ class CacheAttributes(Protocol):
-    cache: Dict[int, Tuple[Any, Any]]
+    cache: dict[int, tuple[Any, Any]]
diff --git a/out/upstream/scipy/scipy/optimize/_direct_py.pyi b/out/local/scipy/scipy/optimize/_direct_py.pyi
index 2a42aa05f..69ea3b369 100644
--- a/out/upstream/scipy/scipy/optimize/_direct_py.pyi
+++ b/out/local/scipy/scipy/optimize/_direct_py.pyi
@@ -4 +4 @@ from scipy.optimize import OptimizeResult
-from typing import Any, Callable, Iterable, Tuple
+from typing import Any, Callable, Iterable
@@ -8 +8 @@ __all__ = ['direct']
-def direct(func: Callable[[npt.ArrayLike, Tuple[Any]], float], bounds: Iterable | Bounds, *, args: tuple = (), eps: float = 0.0001, maxfun: int | None = None, maxiter: int = 1000, locally_biased: bool = True, f_min: float = ..., f_min_rtol: float = 0.0001, vol_tol: float = 1e-16, len_tol: float = 1e-06, callback: Callable[[npt.ArrayLike], None] | None = None) -> OptimizeResult: ...
+def direct(func: Callable[[npt.ArrayLike, tuple[Any]], float], bounds: Iterable | Bounds, *, args: tuple = (), eps: float = 0.0001, maxfun: int | None = None, maxiter: int = 1000, locally_biased: bool = True, f_min: float = ..., f_min_rtol: float = 0.0001, vol_tol: float = 1e-16, len_tol: float = 1e-06, callback: Callable[[npt.ArrayLike], None] | None = None) -> OptimizeResult: ...
diff --git a/out/upstream/scipy/scipy/optimize/_trustregion_constr/report.pyi b/out/local/scipy/scipy/optimize/_trustregion_constr/report.pyi
index a78301a27..7dbf341a0 100644
--- a/out/upstream/scipy/scipy/optimize/_trustregion_constr/report.pyi
+++ b/out/local/scipy/scipy/optimize/_trustregion_constr/report.pyi
@@ -2 +1,0 @@ from _typeshed import Incomplete
-from typing import List
@@ -5,3 +4,3 @@ class ReportBase:
-    COLUMN_NAMES: List[str]
-    COLUMN_WIDTHS: List[int]
-    ITERATION_FORMATS: List[str]
+    COLUMN_NAMES: list[str]
+    COLUMN_WIDTHS: list[int]
+    ITERATION_FORMATS: list[str]
diff --git a/out/upstream/scipy/scipy/spatial/distance.pyi b/out/local/scipy/scipy/spatial/distance.pyi
index fd1e749e1..a421834a8 100644
--- a/out/upstream/scipy/scipy/spatial/distance.pyi
+++ b/out/local/scipy/scipy/spatial/distance.pyi
@@ -3 +3 @@ from _typeshed import Incomplete
-from typing import Callable, List, Set
+from typing import Callable
@@ -60 +60 @@ class MetricInfo:
-    aka: Set[str]
+    aka: set[str]
@@ -65 +65 @@ class MetricInfo:
-    types: List[str] = ...
+    types: list[str] = ...
diff --git a/out/upstream/scipy/scipy/special/_add_newdocs.pyi b/out/local/scipy/scipy/special/_add_newdocs.pyi
index 3261d1200..89431569a 100644
--- a/out/upstream/scipy/scipy/special/_add_newdocs.pyi
+++ b/out/local/scipy/scipy/special/_add_newdocs.pyi
@@ -1,3 +1 @@
-from typing import Dict
-
-docdict: Dict[str, str]
+docdict: dict[str, str]
diff --git a/out/upstream/seaborn/seaborn/_core/properties.pyi b/out/local/seaborn/seaborn/_core/properties.pyi
index 2fd6e8c63..7c9a3de2f 100644
--- a/out/upstream/seaborn/seaborn/_core/properties.pyi
+++ b/out/local/seaborn/seaborn/_core/properties.pyi
@@ -10 +10 @@ from seaborn.utils import get_color_cycle as get_color_cycle
-from typing import Any, Callable, List, Tuple
+from typing import Any, Callable
@@ -12,2 +12,2 @@ from typing import Any, Callable, List, Tuple
-RGBTuple = Tuple[float, float, float]
-RGBATuple = Tuple[float, float, float, float]
+RGBTuple = tuple[float, float, float]
+RGBATuple = tuple[float, float, float, float]
@@ -15,3 +15,3 @@ ColorSpec = RGBTuple | RGBATuple | str
-DashPattern = Tuple[float, ...]
-DashPatternWithOffset = Tuple[float, DashPattern | None]
-MarkerPattern = float | str | Tuple[int, int, float] | List[Tuple[float, float]] | Path | MarkerStyle
+DashPattern = tuple[float, ...]
+DashPatternWithOffset = tuple[float, DashPattern | None]
+MarkerPattern = float | str | tuple[int, int, float] | list[tuple[float, float]] | Path | MarkerStyle
diff --git a/out/upstream/seaborn/seaborn/_core/scales.pyi b/out/local/seaborn/seaborn/_core/scales.pyi
index 49208bed9..32bee8061 100644
--- a/out/upstream/seaborn/seaborn/_core/scales.pyi
+++ b/out/local/seaborn/seaborn/_core/scales.pyi
@@ -13 +13 @@ from seaborn._core.typing import Default as Default, default as default
-from typing import Any, Callable, Tuple
+from typing import Any, Callable
@@ -15 +15 @@ from typing import Any, Callable, Tuple
-TransFuncs = Tuple[Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]]
+TransFuncs = tuple[Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]]
diff --git a/out/upstream/seaborn/seaborn/_core/typing.pyi b/out/local/seaborn/seaborn/_core/typing.pyi
index 327410e3e..30cafa444 100644
--- a/out/upstream/seaborn/seaborn/_core/typing.pyi
+++ b/out/local/seaborn/seaborn/_core/typing.pyi
@@ -7 +7 @@ from pandas import Index, Series, Timedelta, Timestamp
-from typing import Any, Dict, List, Tuple
+from typing import Any
@@ -12 +12 @@ VariableSpec = ColumnName | Vector | None
-VariableSpecList = List[VariableSpec] | Index | None
+VariableSpecList = list[VariableSpec] | Index | None
@@ -15 +15 @@ OrderSpec = Iterable | None
-NormSpec = Tuple[float | None, float | None] | Normalize | None
+NormSpec = tuple[float | None, float | None] | Normalize | None
@@ -18 +18 @@ DiscreteValueSpec = dict | list | None
-ContinuousValueSpec = Tuple[float, float] | List[float] | Dict[Any, float] | None
+ContinuousValueSpec = tuple[float, float] | list[float] | dict[Any, float] | None
diff --git a/out/upstream/seaborn/seaborn/external/version.pyi b/out/local/seaborn/seaborn/external/version.pyi
index ba535fc2c..36c08895f 100644
--- a/out/upstream/seaborn/seaborn/external/version.pyi
+++ b/out/local/seaborn/seaborn/external/version.pyi
@@ -2 +2 @@ from _typeshed import Incomplete
-from typing import Callable, NamedTuple, Tuple
+from typing import Callable, NamedTuple
@@ -26 +26 @@ InfiniteTypes = InfinityType | NegativeInfinityType
-PrePostDevType = InfiniteTypes | Tuple[str, int]
+PrePostDevType = InfiniteTypes | tuple[str, int]
@@ -28,3 +28,3 @@ SubLocalType = InfiniteTypes | int | str
-LocalType = NegativeInfinityType | Tuple[SubLocalType | Tuple[SubLocalType, str] | Tuple[NegativeInfinityType, SubLocalType], ...]
-CmpKey = Tuple[int, Tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType]
-LegacyCmpKey = Tuple[int, Tuple[str, ...]]
+LocalType = NegativeInfinityType | tuple[SubLocalType | tuple[SubLocalType, str] | tuple[NegativeInfinityType, SubLocalType], ...]
+CmpKey = tuple[int, tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType]
+LegacyCmpKey = tuple[int, tuple[str, ...]]
@@ -59 +59 @@ class Version(_BaseVersion):
-    def release(self) -> Tuple[int, ...]: ...
+    def release(self) -> tuple[int, ...]: ...
@@ -61 +61 @@ class Version(_BaseVersion):
-    def pre(self) -> Tuple[str, int] | None: ...
+    def pre(self) -> tuple[str, int] | None: ...

This comment has been minimized.

@hamdanal hamdanal changed the title stubgen: Replace obsolete typing aliases to builtin containers stubgen: Replace obsolete typing aliases with builtin containers Jan 19, 2024

This comment has been minimized.

from typing_extensions import List, Type

# builtins are not builtins
tuple = int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also define _tuple here to make sure we handle that correctly? If I recall correctly we just keep adding more underscores in the generated stub.

Suggested change
tuple = int
tuple = int
_tuple = range

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly we just keep adding more underscores in the generated stub.

Turns out we weren't. It didn't cause a lot of trouble because as long as you didn't use the --include-private flag, prefixing the name with a single _ was enough.
Fixed in cdbde86.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit 46ebaca into python:master Feb 18, 2024
19 checks passed
@hamdanal hamdanal deleted the stubgen-builtin-containers branch February 18, 2024 21:51
hamdanal added a commit to hamdanal/mypy that referenced this pull request Feb 20, 2024
…hon#16780)

Addresses part of python#16737

This only replaces typing symbols that have equivalents in the
`builtins` module. Replacing other symbols, like those from the
`collections.abc` module, are a bit more complicated so I suggest we
handle them separately.

I also changed the default `TypedDict` module from `typing_extensions`
to `typing` as typeshed dropped support for Python 3.7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants