summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <43369155+BvB93@users.noreply.github.com>2021-12-21 17:23:24 +0100
committerBas van Beek <43369155+BvB93@users.noreply.github.com>2021-12-22 00:08:15 +0100
commit99ed44df750fedfc0bbf956c88d15befd5e760cd (patch)
tree78820b19ae6c0fe62065f87c567066fa112a4aaf
parent08053b2600f4b93575d8057238861219a1a57edc (diff)
downloadnumpy-99ed44df750fedfc0bbf956c88d15befd5e760cd.tar.gz
STY: Replace `Union` with the `|` operator
-rw-r--r--numpy/__init__.pyi120
-rw-r--r--numpy/core/_asarray.pyi6
-rw-r--r--numpy/core/_type_aliases.pyi4
-rw-r--r--numpy/core/_ufunc_config.pyi8
-rw-r--r--numpy/core/arrayprint.pyi2
-rw-r--r--numpy/core/einsumfunc.pyi4
-rw-r--r--numpy/core/fromnumeric.pyi11
-rw-r--r--numpy/core/multiarray.pyi8
-rw-r--r--numpy/lib/_version.pyi14
-rw-r--r--numpy/lib/arraysetops.pyi1
-rw-r--r--numpy/lib/index_tricks.pyi5
-rw-r--r--numpy/lib/ufunclike.pyi4
-rw-r--r--numpy/lib/utils.pyi7
-rw-r--r--numpy/random/_generator.pyi46
-rw-r--r--numpy/random/_mt19937.pyi4
-rw-r--r--numpy/random/_pcg64.pyi6
-rw-r--r--numpy/random/_philox.pyi8
-rw-r--r--numpy/random/_sfc64.pyi4
-rw-r--r--numpy/random/bit_generator.pyi20
-rw-r--r--numpy/random/mtrand.pyi38
-rw-r--r--numpy/typing/_callable.pyi11
-rw-r--r--numpy/typing/tests/data/reveal/nbit_base_example.pyi6
22 files changed, 159 insertions, 178 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 4c3e34072..039b9dfa7 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -949,11 +949,11 @@ class flatiter(Generic[_NdArraySubClass]):
@overload
def __getitem__(
self: flatiter[ndarray[Any, dtype[_ScalarType]]],
- key: Union[int, integer],
+ key: int | integer,
) -> _ScalarType: ...
@overload
def __getitem__(
- self, key: Union[_ArrayLikeInt, slice, ellipsis],
+ self, key: _ArrayLikeInt | slice | ellipsis
) -> _NdArraySubClass: ...
@overload
def __array__(self: flatiter[ndarray[Any, _DType]], dtype: None = ..., /) -> ndarray[Any, _DType]: ...
@@ -1121,7 +1121,7 @@ class _ArrayOrScalarCommon:
self,
axis: None | SupportsIndex = ...,
kind: None | _SortKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> ndarray: ...
@overload
@@ -1519,20 +1519,20 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
) -> ndarray[_ShapeType2, _DType]: ...
@overload
- def __getitem__(self, key: Union[
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[SupportsIndex | _ArrayLikeInt_co, ...],
- ]) -> Any: ...
+ def __getitem__(self, key: (
+ SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[SupportsIndex | _ArrayLikeInt_co, ...]
+ )) -> Any: ...
@overload
- def __getitem__(self, key: Union[
- None,
- slice,
- ellipsis,
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...],
- ]) -> ndarray[Any, _DType_co]: ...
+ def __getitem__(self, key: (
+ None
+ | slice
+ | ellipsis
+ | SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
+ )) -> ndarray[Any, _DType_co]: ...
@overload
def __getitem__(self: NDArray[void], key: str) -> NDArray[Any]: ...
@overload
@@ -1582,7 +1582,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def squeeze(
self,
- axis: Union[SupportsIndex, Tuple[SupportsIndex, ...]] = ...,
+ axis: SupportsIndex | Tuple[SupportsIndex, ...] = ...,
) -> ndarray[Any, _DType_co]: ...
def swapaxes(
@@ -1601,7 +1601,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
kth: _ArrayLikeInt_co,
axis: None | SupportsIndex = ...,
kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> ndarray[Any, _dtype[intp]]: ...
def diagonal(
@@ -1628,7 +1628,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
kth: _ArrayLikeInt_co,
axis: SupportsIndex = ...,
kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> None: ...
# `put` is technically available to `generic`,
@@ -1666,7 +1666,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
self,
axis: SupportsIndex = ...,
kind: None | _SortKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> None: ...
@overload
@@ -2592,7 +2592,7 @@ class generic(_ArrayOrScalarCommon):
) -> ndarray[Any, _dtype[_ScalarType]]: ...
def squeeze(
- self: _ScalarType, axis: Union[L[0], Tuple[()]] = ...
+ self: _ScalarType, axis: L[0] | Tuple[()] = ...
) -> _ScalarType: ...
def transpose(self: _ScalarType, axes: Tuple[()] = ..., /) -> _ScalarType: ...
# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
@@ -3272,7 +3272,7 @@ class AxisError(ValueError, IndexError):
@overload
def __init__(self, axis: int, ndim: int, msg_prefix: None | str = ...) -> None: ...
-_CallType = TypeVar("_CallType", bound=Union[_ErrFunc, _SupportsWrite[str]])
+_CallType = TypeVar("_CallType", bound=_ErrFunc | _SupportsWrite[str])
class errstate(Generic[_CallType], ContextDecorator):
call: _CallType
@@ -3327,7 +3327,7 @@ class ndindex:
class DataSource:
def __init__(
self,
- destpath: Union[None, str, os.PathLike[str]] = ...,
+ destpath: None | str | os.PathLike[str] = ...,
) -> None: ...
def __del__(self) -> None: ...
def abspath(self, path: str) -> str: ...
@@ -3478,29 +3478,29 @@ class recarray(ndarray[_ShapeType, _DType_co]):
def __getattribute__(self, attr: str) -> Any: ...
def __setattr__(self, attr: str, val: ArrayLike) -> None: ...
@overload
- def __getitem__(self, indx: Union[
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[SupportsIndex | _ArrayLikeInt_co, ...],
- ]) -> Any: ...
- @overload
- def __getitem__(self: recarray[Any, dtype[void]], indx: Union[
- None,
- slice,
- ellipsis,
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...],
- ]) -> recarray[Any, _DType_co]: ...
- @overload
- def __getitem__(self, indx: Union[
- None,
- slice,
- ellipsis,
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...],
- ]) -> ndarray[Any, _DType_co]: ...
+ def __getitem__(self, indx: (
+ SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[SupportsIndex | _ArrayLikeInt_co, ...]
+ )) -> Any: ...
+ @overload
+ def __getitem__(self: recarray[Any, dtype[void]], indx: (
+ None
+ | slice
+ | ellipsis
+ | SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
+ )) -> recarray[Any, _DType_co]: ...
+ @overload
+ def __getitem__(self, indx: (
+ None
+ | slice
+ | ellipsis
+ | SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
+ )) -> ndarray[Any, _DType_co]: ...
@overload
def __getitem__(self, indx: str) -> NDArray[Any]: ...
@overload
@@ -3781,20 +3781,20 @@ class matrix(ndarray[_ShapeType, _DType_co]):
def __array_finalize__(self, obj: NDArray[Any]) -> None: ...
@overload
- def __getitem__(self, key: Union[
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[SupportsIndex | _ArrayLikeInt_co, ...],
- ]) -> Any: ...
- @overload
- def __getitem__(self, key: Union[
- None,
- slice,
- ellipsis,
- SupportsIndex,
- _ArrayLikeInt_co,
- Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...],
- ]) -> matrix[Any, _DType_co]: ...
+ def __getitem__(self, key: (
+ SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[SupportsIndex | _ArrayLikeInt_co, ...]
+ )) -> Any: ...
+ @overload
+ def __getitem__(self, key: (
+ None
+ | slice
+ | ellipsis
+ | SupportsIndex
+ | _ArrayLikeInt_co
+ | Tuple[None | slice | ellipsis | _ArrayLikeInt_co | SupportsIndex, ...]
+ )) -> matrix[Any, _DType_co]: ...
@overload
def __getitem__(self: NDArray[void], key: str) -> matrix[Any, dtype[Any]]: ...
@overload
diff --git a/numpy/core/_asarray.pyi b/numpy/core/_asarray.pyi
index fee9b7b6e..477b59c7d 100644
--- a/numpy/core/_asarray.pyi
+++ b/numpy/core/_asarray.pyi
@@ -19,7 +19,7 @@ _RequirementsWithE = Union[_Requirements, _E]
def require(
a: _ArrayType,
dtype: None = ...,
- requirements: Union[None, _Requirements, Iterable[_Requirements]] = ...,
+ requirements: None | _Requirements | Iterable[_Requirements] = ...,
*,
like: ArrayLike = ...
) -> _ArrayType: ...
@@ -27,7 +27,7 @@ def require(
def require(
a: object,
dtype: DTypeLike = ...,
- requirements: Union[_E, Iterable[_RequirementsWithE]] = ...,
+ requirements: _E | Iterable[_RequirementsWithE] = ...,
*,
like: ArrayLike = ...
) -> ndarray: ...
@@ -35,7 +35,7 @@ def require(
def require(
a: object,
dtype: DTypeLike = ...,
- requirements: Union[None, _Requirements, Iterable[_Requirements]] = ...,
+ requirements: None | _Requirements | Iterable[_Requirements] = ...,
*,
like: ArrayLike = ...
) -> ndarray: ...
diff --git a/numpy/core/_type_aliases.pyi b/numpy/core/_type_aliases.pyi
index c10d072f9..660b1d2b6 100644
--- a/numpy/core/_type_aliases.pyi
+++ b/numpy/core/_type_aliases.pyi
@@ -1,4 +1,4 @@
-from typing import Dict, Union, Type, List, TypedDict
+from typing import Dict, Type, List, TypedDict
from numpy import generic, signedinteger, unsignedinteger, floating, complexfloating
@@ -9,5 +9,5 @@ class _SCTypes(TypedDict):
complex: List[Type[complexfloating]]
others: List[type]
-sctypeDict: Dict[Union[int, str], Type[generic]]
+sctypeDict: Dict[int | str, Type[generic]]
sctypes: _SCTypes
diff --git a/numpy/core/_ufunc_config.pyi b/numpy/core/_ufunc_config.pyi
index 7e1b39be9..1688221a9 100644
--- a/numpy/core/_ufunc_config.pyi
+++ b/numpy/core/_ufunc_config.pyi
@@ -1,4 +1,4 @@
-from typing import Union, Callable, Any, Literal, TypedDict
+from typing import Callable, Any, Literal, TypedDict
from numpy import _SupportsWrite
@@ -29,8 +29,8 @@ def geterr() -> _ErrDict: ...
def setbufsize(size: int) -> int: ...
def getbufsize() -> int: ...
def seterrcall(
- func: Union[None, _ErrFunc, _SupportsWrite[str]]
-) -> Union[None, _ErrFunc, _SupportsWrite[str]]: ...
-def geterrcall() -> Union[None, _ErrFunc, _SupportsWrite[str]]: ...
+ func: None | _ErrFunc | _SupportsWrite[str]
+) -> None | _ErrFunc | _SupportsWrite[str]: ...
+def geterrcall() -> None | _ErrFunc | _SupportsWrite[str]: ...
# See `numpy/__init__.pyi` for the `errstate` class
diff --git a/numpy/core/arrayprint.pyi b/numpy/core/arrayprint.pyi
index b18a554d6..5c33a21d3 100644
--- a/numpy/core/arrayprint.pyi
+++ b/numpy/core/arrayprint.pyi
@@ -1,5 +1,5 @@
from types import TracebackType
-from typing import Any, Callable, Union, Type, Literal, TypedDict, SupportsIndex
+from typing import Any, Callable, Type, Literal, TypedDict, SupportsIndex
# Using a private class is by no means ideal, but it is simply a consequence
# of a `contextlib.context` returning an instance of aforementioned class
diff --git a/numpy/core/einsumfunc.pyi b/numpy/core/einsumfunc.pyi
index 9c020f8ba..ec34c3c92 100644
--- a/numpy/core/einsumfunc.pyi
+++ b/numpy/core/einsumfunc.pyi
@@ -30,9 +30,7 @@ _ArrayType = TypeVar(
bound=ndarray[Any, dtype[Union[bool_, number[Any]]]],
)
-_OptimizeKind = Union[
- None, bool, Literal["greedy", "optimal"], Sequence[Any]
-]
+_OptimizeKind = None | bool | Literal["greedy", "optimal"] | Sequence[Any]
_CastingSafe = Literal["no", "equiv", "safe", "same_kind"]
_CastingUnsafe = Literal["unsafe"]
diff --git a/numpy/core/fromnumeric.pyi b/numpy/core/fromnumeric.pyi
index b09ed19da..12847ae4f 100644
--- a/numpy/core/fromnumeric.pyi
+++ b/numpy/core/fromnumeric.pyi
@@ -18,6 +18,7 @@ from numpy import (
from numpy.typing import (
DTypeLike,
ArrayLike,
+ NDArray,
_ShapeLike,
_Shape,
_ArrayLikeBool_co,
@@ -86,7 +87,7 @@ def swapaxes(
def transpose(
a: ArrayLike,
- axes: Union[None, Sequence[int], ndarray] = ...
+ axes: None | Sequence[int] | NDArray[Any] = ...
) -> ndarray: ...
def partition(
@@ -94,7 +95,7 @@ def partition(
kth: _ArrayLikeInt_co,
axis: None | int = ...,
kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> ndarray: ...
def argpartition(
@@ -102,21 +103,21 @@ def argpartition(
kth: _ArrayLikeInt_co,
axis: None | int = ...,
kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> Any: ...
def sort(
a: ArrayLike,
axis: None | int = ...,
kind: None | _SortKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> ndarray: ...
def argsort(
a: ArrayLike,
axis: None | int = ...,
kind: None | _SortKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
+ order: None | str | Sequence[str] = ...,
) -> ndarray: ...
@overload
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
index 62b4b8bfc..b410ffe21 100644
--- a/numpy/core/multiarray.pyi
+++ b/numpy/core/multiarray.pyi
@@ -295,14 +295,14 @@ def unravel_index(
def ravel_multi_index( # type: ignore[misc]
multi_index: Sequence[_IntLike_co],
dims: Sequence[SupportsIndex],
- mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ mode: _ModeKind | Tuple[_ModeKind, ...] = ...,
order: _OrderCF = ...,
) -> intp: ...
@overload
def ravel_multi_index(
multi_index: Sequence[_ArrayLikeInt_co],
dims: Sequence[SupportsIndex],
- mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ mode: _ModeKind | Tuple[_ModeKind, ...] = ...,
order: _OrderCF = ...,
) -> NDArray[intp]: ...
@@ -382,7 +382,7 @@ def lexsort(
) -> Any: ...
def can_cast(
- from_: Union[ArrayLike, DTypeLike],
+ from_: ArrayLike | DTypeLike,
to: DTypeLike,
casting: None | _CastingKind = ...,
) -> bool: ...
@@ -392,7 +392,7 @@ def min_scalar_type(
) -> dtype[Any]: ...
def result_type(
- *arrays_and_dtypes: Union[ArrayLike, DTypeLike],
+ *arrays_and_dtypes: ArrayLike | DTypeLike,
) -> dtype[Any]: ...
@overload
diff --git a/numpy/lib/_version.pyi b/numpy/lib/_version.pyi
index 3581d639b..e8b5026ca 100644
--- a/numpy/lib/_version.pyi
+++ b/numpy/lib/_version.pyi
@@ -1,4 +1,4 @@
-from typing import Union, List
+from typing import List
__all__: List[str]
@@ -11,9 +11,9 @@ class NumpyVersion:
pre_release: str
is_devversion: bool
def __init__(self, vstring: str) -> None: ...
- def __lt__(self, other: Union[str, NumpyVersion]) -> bool: ...
- def __le__(self, other: Union[str, NumpyVersion]) -> bool: ...
- def __eq__(self, other: Union[str, NumpyVersion]) -> bool: ... # type: ignore[override]
- def __ne__(self, other: Union[str, NumpyVersion]) -> bool: ... # type: ignore[override]
- def __gt__(self, other: Union[str, NumpyVersion]) -> bool: ...
- def __ge__(self, other: Union[str, NumpyVersion]) -> bool: ...
+ def __lt__(self, other: str | NumpyVersion) -> bool: ...
+ def __le__(self, other: str | NumpyVersion) -> bool: ...
+ def __eq__(self, other: str | NumpyVersion) -> bool: ... # type: ignore[override]
+ def __ne__(self, other: str | NumpyVersion) -> bool: ... # type: ignore[override]
+ def __gt__(self, other: str | NumpyVersion) -> bool: ...
+ def __ge__(self, other: str | NumpyVersion) -> bool: ...
diff --git a/numpy/lib/arraysetops.pyi b/numpy/lib/arraysetops.pyi
index 6f13ec74b..492affb10 100644
--- a/numpy/lib/arraysetops.pyi
+++ b/numpy/lib/arraysetops.pyi
@@ -2,7 +2,6 @@ from typing import (
Literal as L,
Any,
List,
- Union,
TypeVar,
Tuple,
overload,
diff --git a/numpy/lib/index_tricks.pyi b/numpy/lib/index_tricks.pyi
index d16faf81a..6aa8b2571 100644
--- a/numpy/lib/index_tricks.pyi
+++ b/numpy/lib/index_tricks.pyi
@@ -5,7 +5,6 @@ from typing import (
Generic,
overload,
List,
- Union,
Sequence,
Literal,
SupportsIndex,
@@ -79,12 +78,12 @@ class nd_grid(Generic[_BoolType]):
@overload
def __getitem__(
self: nd_grid[Literal[False]],
- key: Union[slice, Sequence[slice]],
+ key: slice | Sequence[slice],
) -> NDArray[Any]: ...
@overload
def __getitem__(
self: nd_grid[Literal[True]],
- key: Union[slice, Sequence[slice]],
+ key: slice | Sequence[slice],
) -> List[NDArray[Any]]: ...
class MGridClass(nd_grid[Literal[False]]):
diff --git a/numpy/lib/ufunclike.pyi b/numpy/lib/ufunclike.pyi
index 03f08ebff..bd48816e5 100644
--- a/numpy/lib/ufunclike.pyi
+++ b/numpy/lib/ufunclike.pyi
@@ -1,4 +1,4 @@
-from typing import Any, overload, TypeVar, List, Union
+from typing import Any, overload, TypeVar, List
from numpy import floating, bool_, object_, ndarray
from numpy.typing import (
@@ -29,7 +29,7 @@ def fix(
) -> NDArray[object_]: ...
@overload
def fix(
- x: Union[_ArrayLikeFloat_co, _ArrayLikeObject_co],
+ x: _ArrayLikeFloat_co | _ArrayLikeObject_co,
out: _ArrayType,
) -> _ArrayType: ...
diff --git a/numpy/lib/utils.pyi b/numpy/lib/utils.pyi
index f42ba9efb..ef4f8cd4a 100644
--- a/numpy/lib/utils.pyi
+++ b/numpy/lib/utils.pyi
@@ -8,7 +8,6 @@ from typing import (
Sequence,
Tuple,
TypeVar,
- Union,
Protocol,
)
@@ -67,7 +66,7 @@ def deprecate_with_doc(msg: None | str) -> _Deprecate: ...
# implementing the `__array_interface__` protocol. The caveat is
# that certain keys, marked as optional in the spec, must be present for
# `byte_bounds`. This concerns `"strides"` and `"data"`.
-def byte_bounds(a: Union[generic, ndarray[Any, Any]]) -> Tuple[int, int]: ...
+def byte_bounds(a: generic | ndarray[Any, Any]) -> Tuple[int, int]: ...
def who(vardict: None | Mapping[str, ndarray[Any, Any]] = ...) -> None: ...
@@ -85,10 +84,10 @@ def source(
def lookfor(
what: str,
- module: Union[None, str, Sequence[str]] = ...,
+ module: None | str | Sequence[str] = ...,
import_modules: bool = ...,
regenerate: bool = ...,
output: None | _SupportsWrite[str] =...,
) -> None: ...
-def safe_eval(source: Union[str, AST]) -> Any: ...
+def safe_eval(source: str | AST) -> Any: ...
diff --git a/numpy/random/_generator.pyi b/numpy/random/_generator.pyi
index 11499501e..a1e25871a 100644
--- a/numpy/random/_generator.pyi
+++ b/numpy/random/_generator.pyi
@@ -76,7 +76,7 @@ class Generator:
def standard_normal( # type: ignore[misc]
self,
size: None = ...,
- dtype: Union[_DTypeLikeFloat32, _DTypeLikeFloat64] = ...,
+ dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
out: None = ...,
) -> float: ...
@overload
@@ -112,7 +112,7 @@ class Generator:
def standard_exponential( # type: ignore[misc]
self,
size: None = ...,
- dtype: Union[_DTypeLikeFloat32, _DTypeLikeFloat64] = ...,
+ dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
method: Literal["zig", "inv"] = ...,
out: None = ...,
) -> float: ...
@@ -155,7 +155,7 @@ class Generator:
def random( # type: ignore[misc]
self,
size: None = ...,
- dtype: Union[_DTypeLikeFloat32, _DTypeLikeFloat64] = ...,
+ dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
out: None = ...,
) -> float: ...
@overload
@@ -218,7 +218,7 @@ class Generator:
low: int,
high: None | int = ...,
size: None = ...,
- dtype: Union[_DTypeLikeInt, _DTypeLikeUInt] = ...,
+ dtype: _DTypeLikeInt | _DTypeLikeUInt = ...,
endpoint: bool = ...,
) -> int: ...
@overload
@@ -243,7 +243,7 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int8], Type[int8], _Int8Codes, _SupportsDType[dtype[int8]]] = ...,
+ dtype: dtype[int8] | Type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int8]]: ...
@overload
@@ -252,7 +252,7 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int16], Type[int16], _Int16Codes, _SupportsDType[dtype[int16]]] = ...,
+ dtype: dtype[int16] | Type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int16]]: ...
@overload
@@ -261,16 +261,16 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int32], Type[int32], _Int32Codes, _SupportsDType[dtype[int32]]] = ...,
+ dtype: dtype[int32] | Type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
endpoint: bool = ...,
- ) -> ndarray[Any, dtype[Union[int32]]]: ...
+ ) -> ndarray[Any, dtype[int32]]: ...
@overload
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: None | Union[dtype[int64], Type[int64], _Int64Codes, _SupportsDType[dtype[int64]]] = ...,
+ dtype: None | dtype[int64] | Type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int64]]: ...
@overload
@@ -279,7 +279,7 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[uint8], Type[uint8], _UInt8Codes, _SupportsDType[dtype[uint8]]] = ...,
+ dtype: dtype[uint8] | Type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint8]]: ...
@overload
@@ -288,20 +288,16 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint16], Type[uint16], _UInt16Codes, _SupportsDType[dtype[uint16]]
- ] = ...,
+ dtype: dtype[uint16] | Type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
endpoint: bool = ...,
- ) -> ndarray[Any, dtype[Union[uint16]]]: ...
+ ) -> ndarray[Any, dtype[uint16]]: ...
@overload
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint32], Type[uint32], _UInt32Codes, _SupportsDType[dtype[uint32]]
- ] = ...,
+ dtype: dtype[uint32] | Type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint32]]: ...
@overload
@@ -310,9 +306,7 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint64], Type[uint64], _UInt64Codes, _SupportsDType[dtype[uint64]]
- ] = ...,
+ dtype: dtype[uint64] | Type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint64]]: ...
@overload
@@ -321,9 +315,7 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[int_], Type[int], Type[int_], _IntCodes, _SupportsDType[dtype[int_]]
- ] = ...,
+ dtype: dtype[int_] | Type[int] | Type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
@@ -332,10 +324,10 @@ class Generator:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[uint], Type[uint], _UIntCodes, _SupportsDType[dtype[uint]]] = ...,
+ dtype: dtype[uint] | Type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint]]: ...
- # TODO: Use a TypeVar _T here to get away from Any output? Should be int->ndarray[Any,dtype[int64]], ArrayLike[_T] -> Union[_T, ndarray[Any,Any]]
+ # TODO: Use a TypeVar _T here to get away from Any output? Should be int->ndarray[Any,dtype[int64]], ArrayLike[_T] -> _T | ndarray[Any,Any]
@overload
def choice(
self,
@@ -399,7 +391,7 @@ class Generator:
self,
shape: float,
size: None = ...,
- dtype: Union[_DTypeLikeFloat32, _DTypeLikeFloat64] = ...,
+ dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
out: None = ...,
) -> float: ...
@overload
@@ -641,5 +633,5 @@ class Generator:
def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ...
def default_rng(
- seed: Union[None, _ArrayLikeInt_co, SeedSequence, BitGenerator, Generator] = ...
+ seed: None | _ArrayLikeInt_co | SeedSequence | BitGenerator | Generator = ...
) -> Generator: ...
diff --git a/numpy/random/_mt19937.pyi b/numpy/random/_mt19937.pyi
index 820f27392..1494aad59 100644
--- a/numpy/random/_mt19937.pyi
+++ b/numpy/random/_mt19937.pyi
@@ -1,4 +1,4 @@
-from typing import Any, Union, TypedDict
+from typing import Any, TypedDict
from numpy import dtype, ndarray, uint32
from numpy.random.bit_generator import BitGenerator, SeedSequence
@@ -13,7 +13,7 @@ class _MT19937State(TypedDict):
state: _MT19937Internal
class MT19937(BitGenerator):
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
def _legacy_seeding(self, seed: _ArrayLikeInt_co) -> None: ...
def jumped(self, jumps: int = ...) -> MT19937: ...
@property
diff --git a/numpy/random/_pcg64.pyi b/numpy/random/_pcg64.pyi
index 4881a987e..b1e73565e 100644
--- a/numpy/random/_pcg64.pyi
+++ b/numpy/random/_pcg64.pyi
@@ -1,4 +1,4 @@
-from typing import Union, TypedDict
+from typing import TypedDict
from numpy.random.bit_generator import BitGenerator, SeedSequence
from numpy.typing import _ArrayLikeInt_co
@@ -14,7 +14,7 @@ class _PCG64State(TypedDict):
uinteger: int
class PCG64(BitGenerator):
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
def jumped(self, jumps: int = ...) -> PCG64: ...
@property
def state(
@@ -28,7 +28,7 @@ class PCG64(BitGenerator):
def advance(self, delta: int) -> PCG64: ...
class PCG64DXSM(BitGenerator):
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
def jumped(self, jumps: int = ...) -> PCG64DXSM: ...
@property
def state(
diff --git a/numpy/random/_philox.pyi b/numpy/random/_philox.pyi
index dd1c5e6e9..1f289f5de 100644
--- a/numpy/random/_philox.pyi
+++ b/numpy/random/_philox.pyi
@@ -1,4 +1,4 @@
-from typing import Any, Union, TypedDict
+from typing import Any, TypedDict
from numpy import dtype, ndarray, uint64
from numpy.random.bit_generator import BitGenerator, SeedSequence
@@ -19,9 +19,9 @@ class _PhiloxState(TypedDict):
class Philox(BitGenerator):
def __init__(
self,
- seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...,
- counter: Union[None, _ArrayLikeInt_co] = ...,
- key: Union[None, _ArrayLikeInt_co] = ...,
+ seed: None | _ArrayLikeInt_co | SeedSequence = ...,
+ counter: None | _ArrayLikeInt_co = ...,
+ key: None | _ArrayLikeInt_co = ...,
) -> None: ...
@property
def state(
diff --git a/numpy/random/_sfc64.pyi b/numpy/random/_sfc64.pyi
index 94d11a210..333aa92c4 100644
--- a/numpy/random/_sfc64.pyi
+++ b/numpy/random/_sfc64.pyi
@@ -1,4 +1,4 @@
-from typing import Any, Union, TypedDict
+from typing import Any, TypedDict
from numpy import dtype as dtype
from numpy import ndarray as ndarray
@@ -16,7 +16,7 @@ class _SFC64State(TypedDict):
uinteger: int
class SFC64(BitGenerator):
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
@property
def state(
self,
diff --git a/numpy/random/bit_generator.pyi b/numpy/random/bit_generator.pyi
index 5d8b12651..071301e5d 100644
--- a/numpy/random/bit_generator.pyi
+++ b/numpy/random/bit_generator.pyi
@@ -36,7 +36,7 @@ _DTypeLikeUint64 = Union[
]
class _SeedSeqState(TypedDict):
- entropy: Union[None, int, Sequence[int]]
+ entropy: None | int | Sequence[int]
spawn_key: Tuple[int, ...]
pool_size: int
n_children_spawned: int
@@ -52,8 +52,8 @@ class _Interface(NamedTuple):
class ISeedSequence(abc.ABC):
@abc.abstractmethod
def generate_state(
- self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
- ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
+ self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
+ ) -> ndarray[Any, dtype[uint32 | uint64]]: ...
class ISpawnableSeedSequence(ISeedSequence):
@abc.abstractmethod
@@ -61,19 +61,19 @@ class ISpawnableSeedSequence(ISeedSequence):
class SeedlessSeedSequence(ISpawnableSeedSequence):
def generate_state(
- self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
- ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
+ self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
+ ) -> ndarray[Any, dtype[uint32 | uint64]]: ...
def spawn(self: _T, n_children: int) -> List[_T]: ...
class SeedSequence(ISpawnableSeedSequence):
- entropy: Union[None, int, Sequence[int]]
+ entropy: None | int | Sequence[int]
spawn_key: Tuple[int, ...]
pool_size: int
n_children_spawned: int
pool: ndarray[Any, dtype[uint32]]
def __init__(
self,
- entropy: Union[None, int, Sequence[int], _ArrayLikeInt_co] = ...,
+ entropy: None | int | Sequence[int] | _ArrayLikeInt_co = ...,
*,
spawn_key: Sequence[int] = ...,
pool_size: int = ...,
@@ -85,13 +85,13 @@ class SeedSequence(ISpawnableSeedSequence):
self,
) -> _SeedSeqState: ...
def generate_state(
- self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
- ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
+ self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
+ ) -> ndarray[Any, dtype[uint32 | uint64]]: ...
def spawn(self, n_children: int) -> List[SeedSequence]: ...
class BitGenerator(abc.ABC):
lock: Lock
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
def __getstate__(self) -> Dict[str, Any]: ...
def __setstate__(self, state: Dict[str, Any]) -> None: ...
def __reduce__(
diff --git a/numpy/random/mtrand.pyi b/numpy/random/mtrand.pyi
index 0769ff19e..87bdf8141 100644
--- a/numpy/random/mtrand.pyi
+++ b/numpy/random/mtrand.pyi
@@ -62,7 +62,7 @@ _DTypeLikeFloat64 = Union[
class RandomState:
_bit_generator: BitGenerator
- def __init__(self, seed: Union[None, _ArrayLikeInt_co, BitGenerator] = ...) -> None: ...
+ def __init__(self, seed: None | _ArrayLikeInt_co | BitGenerator = ...) -> None: ...
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
def __getstate__(self) -> Dict[str, Any]: ...
@@ -74,9 +74,9 @@ class RandomState:
@overload
def get_state(
self, legacy: Literal[True] = ...
- ) -> Union[Dict[str, Any], Tuple[str, ndarray[Any, dtype[uint32]], int, int, float]]: ...
+ ) -> Dict[str, Any] | Tuple[str, ndarray[Any, dtype[uint32]], int, int, float]: ...
def set_state(
- self, state: Union[Dict[str, Any], Tuple[str, ndarray[Any, dtype[uint32]], int, int, float]]
+ self, state: Dict[str, Any] | Tuple[str, ndarray[Any, dtype[uint32]], int, int, float]
) -> None: ...
@overload
def random_sample(self, size: None = ...) -> float: ... # type: ignore[misc]
@@ -126,7 +126,7 @@ class RandomState:
low: int,
high: None | int = ...,
size: None = ...,
- dtype: Union[_DTypeLikeInt, _DTypeLikeUInt] = ...,
+ dtype: _DTypeLikeInt | _DTypeLikeUInt = ...,
) -> int: ...
@overload
def randint( # type: ignore[misc]
@@ -149,7 +149,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int8], Type[int8], _Int8Codes, _SupportsDType[dtype[int8]]] = ...,
+ dtype: dtype[int8] | Type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
) -> ndarray[Any, dtype[int8]]: ...
@overload
def randint( # type: ignore[misc]
@@ -157,7 +157,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int16], Type[int16], _Int16Codes, _SupportsDType[dtype[int16]]] = ...,
+ dtype: dtype[int16] | Type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
) -> ndarray[Any, dtype[int16]]: ...
@overload
def randint( # type: ignore[misc]
@@ -165,8 +165,8 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[int32], Type[int32], _Int32Codes, _SupportsDType[dtype[int32]]] = ...,
- ) -> ndarray[Any, dtype[Union[int32]]]: ...
+ dtype: dtype[int32] | Type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
+ ) -> ndarray[Any, dtype[int32]]: ...
@overload
def randint( # type: ignore[misc]
self,
@@ -181,7 +181,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[uint8], Type[uint8], _UInt8Codes, _SupportsDType[dtype[uint8]]] = ...,
+ dtype: dtype[uint8] | Type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
) -> ndarray[Any, dtype[uint8]]: ...
@overload
def randint( # type: ignore[misc]
@@ -189,19 +189,15 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint16], Type[uint16], _UInt16Codes, _SupportsDType[dtype[uint16]]
- ] = ...,
- ) -> ndarray[Any, dtype[Union[uint16]]]: ...
+ dtype: dtype[uint16] | Type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
+ ) -> ndarray[Any, dtype[uint16]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint32], Type[uint32], _UInt32Codes, _SupportsDType[dtype[uint32]]
- ] = ...,
+ dtype: dtype[uint32] | Type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
) -> ndarray[Any, dtype[uint32]]: ...
@overload
def randint( # type: ignore[misc]
@@ -209,9 +205,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[uint64], Type[uint64], _UInt64Codes, _SupportsDType[dtype[uint64]]
- ] = ...,
+ dtype: dtype[uint64] | Type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
) -> ndarray[Any, dtype[uint64]]: ...
@overload
def randint( # type: ignore[misc]
@@ -219,9 +213,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[
- dtype[int_], Type[int], Type[int_], _IntCodes, _SupportsDType[dtype[int_]]
- ] = ...,
+ dtype: dtype[int_] | Type[int] | Type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
def randint( # type: ignore[misc]
@@ -229,7 +221,7 @@ class RandomState:
low: _ArrayLikeInt_co,
high: None | _ArrayLikeInt_co = ...,
size: None | _ShapeLike = ...,
- dtype: Union[dtype[uint], Type[uint], _UIntCodes, _SupportsDType[dtype[uint]]] = ...,
+ dtype: dtype[uint] | Type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
) -> ndarray[Any, dtype[uint]]: ...
def bytes(self, length: int) -> bytes: ...
@overload
diff --git a/numpy/typing/_callable.pyi b/numpy/typing/_callable.pyi
index e1149f26a..59af13e01 100644
--- a/numpy/typing/_callable.pyi
+++ b/numpy/typing/_callable.pyi
@@ -11,7 +11,6 @@ See the `Mypy documentation`_ on protocols for more details.
from __future__ import annotations
from typing import (
- Union,
TypeVar,
overload,
Any,
@@ -310,11 +309,11 @@ class _ComplexOp(Protocol[_NBit1]):
@overload
def __call__(
self,
- other: Union[
- integer[_NBit2],
- floating[_NBit2],
- complexfloating[_NBit2, _NBit2],
- ], /,
+ other: (
+ integer[_NBit2]
+ | floating[_NBit2]
+ | complexfloating[_NBit2, _NBit2]
+ ), /,
) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ...
class _NumberOp(Protocol):
diff --git a/numpy/typing/tests/data/reveal/nbit_base_example.pyi b/numpy/typing/tests/data/reveal/nbit_base_example.pyi
index d34f6f69a..a7cc68194 100644
--- a/numpy/typing/tests/data/reveal/nbit_base_example.pyi
+++ b/numpy/typing/tests/data/reveal/nbit_base_example.pyi
@@ -1,11 +1,13 @@
-from typing import TypeVar, Union
+from __future__ import annotations
+
+from typing import TypeVar
import numpy as np
import numpy.typing as npt
T1 = TypeVar("T1", bound=npt.NBitBase)
T2 = TypeVar("T2", bound=npt.NBitBase)
-def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[Union[T1, T2]]:
+def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[T1 | T2]:
return a + b
i8: np.int64