summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <43369155+BvB93@users.noreply.github.com>2021-12-21 16:33:11 +0100
committerBas van Beek <43369155+BvB93@users.noreply.github.com>2021-12-22 00:08:03 +0100
commit08053b2600f4b93575d8057238861219a1a57edc (patch)
tree9edef76d944cfcbdbb4bcf41516b3cf15f3a9a86
parent509d3ab421142905482592337ea2407bacb351ac (diff)
downloadnumpy-08053b2600f4b93575d8057238861219a1a57edc.tar.gz
STY: Replace `Optional` with the `|` operator
-rw-r--r--numpy/__init__.pyi119
-rw-r--r--numpy/core/_internal.pyi4
-rw-r--r--numpy/core/_ufunc_config.pyi22
-rw-r--r--numpy/core/arrayprint.pyi96
-rw-r--r--numpy/core/einsumfunc.pyi18
-rw-r--r--numpy/core/fromnumeric.pyi104
-rw-r--r--numpy/core/multiarray.pyi51
-rw-r--r--numpy/ctypeslib.pyi3
-rw-r--r--numpy/lib/utils.pyi35
-rw-r--r--numpy/random/_generator.pyi158
-rw-r--r--numpy/random/bit_generator.pyi3
-rw-r--r--numpy/random/mtrand.pyi138
-rw-r--r--numpy/typing/tests/data/pass/array_like.py6
13 files changed, 375 insertions, 382 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index eb1e81c6a..4c3e34072 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -182,7 +182,6 @@ from typing import (
List,
Mapping,
NoReturn,
- Optional,
overload,
Sequence,
Sized,
@@ -961,9 +960,9 @@ class flatiter(Generic[_NdArraySubClass]):
@overload
def __array__(self, dtype: _DType, /) -> ndarray[Any, _DType]: ...
-_OrderKACF = Optional[L["K", "A", "C", "F"]]
-_OrderACF = Optional[L["A", "C", "F"]]
-_OrderCF = Optional[L["C", "F"]]
+_OrderKACF = L[None, "K", "A", "C", "F"]
+_OrderACF = L[None, "A", "C", "F"]
+_OrderCF = L[None, "C", "F"]
_ModeKind = L["raise", "wrap", "clip"]
_PartitionKind = L["introselect"]
@@ -1034,14 +1033,14 @@ class _ArrayOrScalarCommon:
@overload
def all(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: None = ...,
keepdims: bool = ...,
) -> Any: ...
@overload
def all(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
) -> _NdArraySubClass: ...
@@ -1056,14 +1055,14 @@ class _ArrayOrScalarCommon:
@overload
def any(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: None = ...,
keepdims: bool = ...,
) -> Any: ...
@overload
def any(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
) -> _NdArraySubClass: ...
@@ -1087,7 +1086,7 @@ class _ArrayOrScalarCommon:
@overload
def argmax(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
*,
keepdims: bool = ...,
@@ -1112,7 +1111,7 @@ class _ArrayOrScalarCommon:
@overload
def argmin(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
*,
keepdims: bool = ...,
@@ -1120,8 +1119,8 @@ class _ArrayOrScalarCommon:
def argsort(
self,
- axis: Optional[SupportsIndex] = ...,
- kind: Optional[_SortKind] = ...,
+ axis: None | SupportsIndex = ...,
+ kind: None | _SortKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
@@ -1144,7 +1143,7 @@ class _ArrayOrScalarCommon:
def clip(
self,
min: ArrayLike = ...,
- max: Optional[ArrayLike] = ...,
+ max: None | ArrayLike = ...,
out: None = ...,
**kwargs: Any,
) -> ndarray: ...
@@ -1160,7 +1159,7 @@ class _ArrayOrScalarCommon:
def clip(
self,
min: ArrayLike = ...,
- max: Optional[ArrayLike] = ...,
+ max: None | ArrayLike = ...,
out: _NdArraySubClass = ...,
**kwargs: Any,
) -> _NdArraySubClass: ...
@@ -1177,14 +1176,14 @@ class _ArrayOrScalarCommon:
def compress(
self,
a: ArrayLike,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
) -> ndarray: ...
@overload
def compress(
self,
a: ArrayLike,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: _NdArraySubClass = ...,
) -> _NdArraySubClass: ...
@@ -1195,14 +1194,14 @@ class _ArrayOrScalarCommon:
@overload
def cumprod(
self,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
dtype: DTypeLike = ...,
out: None = ...,
) -> ndarray: ...
@overload
def cumprod(
self,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
) -> _NdArraySubClass: ...
@@ -1210,14 +1209,14 @@ class _ArrayOrScalarCommon:
@overload
def cumsum(
self,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
dtype: DTypeLike = ...,
out: None = ...,
) -> ndarray: ...
@overload
def cumsum(
self,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
) -> _NdArraySubClass: ...
@@ -1225,7 +1224,7 @@ class _ArrayOrScalarCommon:
@overload
def max(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: None = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
@@ -1234,7 +1233,7 @@ class _ArrayOrScalarCommon:
@overload
def max(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
@@ -1244,7 +1243,7 @@ class _ArrayOrScalarCommon:
@overload
def mean(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: None = ...,
keepdims: bool = ...,
@@ -1252,7 +1251,7 @@ class _ArrayOrScalarCommon:
@overload
def mean(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
@@ -1261,7 +1260,7 @@ class _ArrayOrScalarCommon:
@overload
def min(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: None = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
@@ -1270,7 +1269,7 @@ class _ArrayOrScalarCommon:
@overload
def min(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
@@ -1285,7 +1284,7 @@ class _ArrayOrScalarCommon:
@overload
def prod(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: None = ...,
keepdims: bool = ...,
@@ -1295,7 +1294,7 @@ class _ArrayOrScalarCommon:
@overload
def prod(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
@@ -1306,14 +1305,14 @@ class _ArrayOrScalarCommon:
@overload
def ptp(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: None = ...,
keepdims: bool = ...,
) -> Any: ...
@overload
def ptp(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
) -> _NdArraySubClass: ...
@@ -1334,7 +1333,7 @@ class _ArrayOrScalarCommon:
@overload
def std(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: None = ...,
ddof: int = ...,
@@ -1343,7 +1342,7 @@ class _ArrayOrScalarCommon:
@overload
def std(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
ddof: int = ...,
@@ -1353,7 +1352,7 @@ class _ArrayOrScalarCommon:
@overload
def sum(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: None = ...,
keepdims: bool = ...,
@@ -1363,7 +1362,7 @@ class _ArrayOrScalarCommon:
@overload
def sum(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
keepdims: bool = ...,
@@ -1374,7 +1373,7 @@ class _ArrayOrScalarCommon:
@overload
def var(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: None = ...,
ddof: int = ...,
@@ -1383,7 +1382,7 @@ class _ArrayOrScalarCommon:
@overload
def var(
self,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
out: _NdArraySubClass = ...,
ddof: int = ...,
@@ -1451,7 +1450,7 @@ class _SupportsImag(Protocol[_T_co]):
class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
@property
- def base(self) -> Optional[ndarray]: ...
+ def base(self) -> None | ndarray: ...
@property
def ndim(self) -> int: ...
@property
@@ -1600,7 +1599,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def argpartition(
self,
kth: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray[Any, _dtype[intp]]: ...
@@ -1646,14 +1645,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
self, # >= 1D array
v: _ScalarLike_co, # 0D array-like
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeInt_co] = ...,
+ sorter: None | _ArrayLikeInt_co = ...,
) -> intp: ...
@overload
def searchsorted(
self, # >= 1D array
v: ArrayLike,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeInt_co] = ...,
+ sorter: None | _ArrayLikeInt_co = ...,
) -> ndarray[Any, _dtype[intp]]: ...
def setfield(
@@ -1666,7 +1665,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def sort(
self,
axis: SupportsIndex = ...,
- kind: Optional[_SortKind] = ...,
+ kind: None | _SortKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> None: ...
@@ -1693,7 +1692,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def take( # type: ignore[misc]
self: ndarray[Any, _dtype[_ScalarType]],
indices: _IntLike_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
mode: _ModeKind = ...,
) -> _ScalarType: ...
@@ -1701,7 +1700,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def take( # type: ignore[misc]
self,
indices: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
mode: _ModeKind = ...,
) -> ndarray[Any, _DType_co]: ...
@@ -1709,7 +1708,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def take(
self,
indices: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: _NdArraySubClass = ...,
mode: _ModeKind = ...,
) -> _NdArraySubClass: ...
@@ -1717,7 +1716,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def repeat(
self,
repeats: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
) -> ndarray[Any, _DType_co]: ...
def flatten(
@@ -2546,7 +2545,7 @@ class generic(_ArrayOrScalarCommon):
def take( # type: ignore[misc]
self: _ScalarType,
indices: _IntLike_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
mode: _ModeKind = ...,
) -> _ScalarType: ...
@@ -2554,7 +2553,7 @@ class generic(_ArrayOrScalarCommon):
def take( # type: ignore[misc]
self: _ScalarType,
indices: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
mode: _ModeKind = ...,
) -> ndarray[Any, _dtype[_ScalarType]]: ...
@@ -2562,7 +2561,7 @@ class generic(_ArrayOrScalarCommon):
def take(
self,
indices: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: _NdArraySubClass = ...,
mode: _ModeKind = ...,
) -> _NdArraySubClass: ...
@@ -2570,7 +2569,7 @@ class generic(_ArrayOrScalarCommon):
def repeat(
self: _ScalarType,
repeats: _ArrayLikeInt_co,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
) -> ndarray[Any, _dtype[_ScalarType]]: ...
def flatten(
@@ -3144,7 +3143,7 @@ class ufunc:
def identity(self) -> Any: ...
# This is None for ufuncs and a string for gufuncs.
@property
- def signature(self) -> Optional[str]: ...
+ def signature(self) -> None | str: ...
# The next four methods will always exist, but they will just
# raise a ValueError ufuncs with that don't accept two input
# arguments and return one output argument. Because of that we
@@ -3284,18 +3283,18 @@ class errstate(Generic[_CallType], ContextDecorator):
self,
*,
call: _CallType = ...,
- all: Optional[_ErrKind] = ...,
- divide: Optional[_ErrKind] = ...,
- over: Optional[_ErrKind] = ...,
- under: Optional[_ErrKind] = ...,
- invalid: Optional[_ErrKind] = ...,
+ all: None | _ErrKind = ...,
+ divide: None | _ErrKind = ...,
+ over: None | _ErrKind = ...,
+ under: None | _ErrKind = ...,
+ invalid: None | _ErrKind = ...,
) -> None: ...
def __enter__(self) -> None: ...
def __exit__(
self,
- exc_type: Optional[Type[BaseException]],
- exc_value: Optional[BaseException],
- traceback: Optional[TracebackType],
+ exc_type: None | Type[BaseException],
+ exc_value: None | BaseException,
+ traceback: None | TracebackType,
/,
) -> None: ...
@@ -3340,8 +3339,8 @@ class DataSource:
self,
path: str,
mode: str = ...,
- encoding: Optional[str] = ...,
- newline: Optional[str] = ...,
+ encoding: None | str = ...,
+ newline: None | str = ...,
) -> IO[Any]: ...
# TODO: The type of each `__next__` and `iters` return-type depends
diff --git a/numpy/core/_internal.pyi b/numpy/core/_internal.pyi
index f4bfd770f..51b2a87dd 100644
--- a/numpy/core/_internal.pyi
+++ b/numpy/core/_internal.pyi
@@ -1,4 +1,4 @@
-from typing import Any, TypeVar, Type, overload, Optional, Generic
+from typing import Any, TypeVar, Type, overload, Generic
import ctypes as ct
from numpy import ndarray
@@ -6,7 +6,7 @@ from numpy.ctypeslib import c_intp
_CastT = TypeVar("_CastT", bound=ct._CanCastTo) # Copied from `ctypes.cast`
_CT = TypeVar("_CT", bound=ct._CData)
-_PT = TypeVar("_PT", bound=Optional[int])
+_PT = TypeVar("_PT", bound=None | int)
# TODO: Let the likes of `shape_as` and `strides_as` return `None`
# for 0D arrays once we've got shape-support
diff --git a/numpy/core/_ufunc_config.pyi b/numpy/core/_ufunc_config.pyi
index cd7129bcb..7e1b39be9 100644
--- a/numpy/core/_ufunc_config.pyi
+++ b/numpy/core/_ufunc_config.pyi
@@ -1,4 +1,4 @@
-from typing import Optional, Union, Callable, Any, Literal, TypedDict
+from typing import Union, Callable, Any, Literal, TypedDict
from numpy import _SupportsWrite
@@ -12,18 +12,18 @@ class _ErrDict(TypedDict):
invalid: _ErrKind
class _ErrDictOptional(TypedDict, total=False):
- all: Optional[_ErrKind]
- divide: Optional[_ErrKind]
- over: Optional[_ErrKind]
- under: Optional[_ErrKind]
- invalid: Optional[_ErrKind]
+ all: None | _ErrKind
+ divide: None | _ErrKind
+ over: None | _ErrKind
+ under: None | _ErrKind
+ invalid: None | _ErrKind
def seterr(
- all: Optional[_ErrKind] = ...,
- divide: Optional[_ErrKind] = ...,
- over: Optional[_ErrKind] = ...,
- under: Optional[_ErrKind] = ...,
- invalid: Optional[_ErrKind] = ...,
+ all: None | _ErrKind = ...,
+ divide: None | _ErrKind = ...,
+ over: None | _ErrKind = ...,
+ under: None | _ErrKind = ...,
+ invalid: None | _ErrKind = ...,
) -> _ErrDict: ...
def geterr() -> _ErrDict: ...
def setbufsize(size: int) -> int: ...
diff --git a/numpy/core/arrayprint.pyi b/numpy/core/arrayprint.pyi
index 0d338206f..b18a554d6 100644
--- a/numpy/core/arrayprint.pyi
+++ b/numpy/core/arrayprint.pyi
@@ -1,5 +1,5 @@
from types import TracebackType
-from typing import Any, Optional, Callable, Union, Type, Literal, TypedDict, SupportsIndex
+from typing import Any, Callable, Union, 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
@@ -50,92 +50,92 @@ class _FormatOptions(TypedDict):
suppress: bool
nanstr: str
infstr: str
- formatter: Optional[_FormatDict]
+ formatter: None | _FormatDict
sign: Literal["-", "+", " "]
floatmode: _FloatMode
legacy: Literal[False, "1.13", "1.21"]
def set_printoptions(
- precision: Optional[SupportsIndex] = ...,
- threshold: Optional[int] = ...,
- edgeitems: Optional[int] = ...,
- linewidth: Optional[int] = ...,
- suppress: Optional[bool] = ...,
- nanstr: Optional[str] = ...,
- infstr: Optional[str] = ...,
- formatter: Optional[_FormatDict] = ...,
- sign: Optional[Literal["-", "+", " "]] = ...,
- floatmode: Optional[_FloatMode] = ...,
+ precision: None | SupportsIndex = ...,
+ threshold: None | int = ...,
+ edgeitems: None | int = ...,
+ linewidth: None | int = ...,
+ suppress: None | bool = ...,
+ nanstr: None | str = ...,
+ infstr: None | str = ...,
+ formatter: None | _FormatDict = ...,
+ sign: Literal[None, "-", "+", " "] = ...,
+ floatmode: None | _FloatMode = ...,
*,
- legacy: Optional[Literal[False, "1.13", "1.21"]] = ...
+ legacy: Literal[None, False, "1.13", "1.21"] = ...
) -> None: ...
def get_printoptions() -> _FormatOptions: ...
def array2string(
a: ndarray[Any, Any],
- max_line_width: Optional[int] = ...,
- precision: Optional[SupportsIndex] = ...,
- suppress_small: Optional[bool] = ...,
+ max_line_width: None | int = ...,
+ precision: None | SupportsIndex = ...,
+ suppress_small: None | bool = ...,
separator: str = ...,
prefix: str = ...,
# NOTE: With the `style` argument being deprecated,
# all arguments between `formatter` and `suffix` are de facto
# keyworld-only arguments
*,
- formatter: Optional[_FormatDict] = ...,
- threshold: Optional[int] = ...,
- edgeitems: Optional[int] = ...,
- sign: Optional[Literal["-", "+", " "]] = ...,
- floatmode: Optional[_FloatMode] = ...,
+ formatter: None | _FormatDict = ...,
+ threshold: None | int = ...,
+ edgeitems: None | int = ...,
+ sign: Literal[None, "-", "+", " "] = ...,
+ floatmode: None | _FloatMode = ...,
suffix: str = ...,
- legacy: Optional[Literal[False, "1.13", "1.21"]] = ...,
+ legacy: Literal[None, False, "1.13", "1.21"] = ...,
) -> str: ...
def format_float_scientific(
x: _FloatLike_co,
- precision: Optional[int] = ...,
+ precision: None | int = ...,
unique: bool = ...,
trim: Literal["k", ".", "0", "-"] = ...,
sign: bool = ...,
- pad_left: Optional[int] = ...,
- exp_digits: Optional[int] = ...,
- min_digits: Optional[int] = ...,
+ pad_left: None | int = ...,
+ exp_digits: None | int = ...,
+ min_digits: None | int = ...,
) -> str: ...
def format_float_positional(
x: _FloatLike_co,
- precision: Optional[int] = ...,
+ precision: None | int = ...,
unique: bool = ...,
fractional: bool = ...,
trim: Literal["k", ".", "0", "-"] = ...,
sign: bool = ...,
- pad_left: Optional[int] = ...,
- pad_right: Optional[int] = ...,
- min_digits: Optional[int] = ...,
+ pad_left: None | int = ...,
+ pad_right: None | int = ...,
+ min_digits: None | int = ...,
) -> str: ...
def array_repr(
arr: ndarray[Any, Any],
- max_line_width: Optional[int] = ...,
- precision: Optional[SupportsIndex] = ...,
- suppress_small: Optional[bool] = ...,
+ max_line_width: None | int = ...,
+ precision: None | SupportsIndex = ...,
+ suppress_small: None | bool = ...,
) -> str: ...
def array_str(
a: ndarray[Any, Any],
- max_line_width: Optional[int] = ...,
- precision: Optional[SupportsIndex] = ...,
- suppress_small: Optional[bool] = ...,
+ max_line_width: None | int = ...,
+ precision: None | SupportsIndex = ...,
+ suppress_small: None | bool = ...,
) -> str: ...
def set_string_function(
- f: Optional[Callable[[ndarray[Any, Any]], str]], repr: bool = ...
+ f: None | Callable[[ndarray[Any, Any]], str], repr: bool = ...
) -> None: ...
def printoptions(
- precision: Optional[SupportsIndex] = ...,
- threshold: Optional[int] = ...,
- edgeitems: Optional[int] = ...,
- linewidth: Optional[int] = ...,
- suppress: Optional[bool] = ...,
- nanstr: Optional[str] = ...,
- infstr: Optional[str] = ...,
- formatter: Optional[_FormatDict] = ...,
- sign: Optional[Literal["-", "+", " "]] = ...,
- floatmode: Optional[_FloatMode] = ...,
+ precision: None | SupportsIndex = ...,
+ threshold: None | int = ...,
+ edgeitems: None | int = ...,
+ linewidth: None | int = ...,
+ suppress: None | bool = ...,
+ nanstr: None | str = ...,
+ infstr: None | str = ...,
+ formatter: None | _FormatDict = ...,
+ sign: Literal[None, "-", "+", " "] = ...,
+ floatmode: None | _FloatMode = ...,
*,
- legacy: Optional[Literal[False, "1.13", "1.21"]] = ...
+ legacy: Literal[None, False, "1.13", "1.21"] = ...
) -> _GeneratorContextManager[_FormatOptions]: ...
diff --git a/numpy/core/einsumfunc.pyi b/numpy/core/einsumfunc.pyi
index aabb04c47..9c020f8ba 100644
--- a/numpy/core/einsumfunc.pyi
+++ b/numpy/core/einsumfunc.pyi
@@ -1,4 +1,4 @@
-from typing import List, TypeVar, Optional, Any, overload, Union, Tuple, Sequence, Literal
+from typing import List, TypeVar, Any, overload, Union, Tuple, Sequence, Literal
from numpy import (
ndarray,
@@ -50,7 +50,7 @@ def einsum(
/,
*operands: _ArrayLikeBool_co,
out: None = ...,
- dtype: Optional[_DTypeLikeBool] = ...,
+ dtype: None | _DTypeLikeBool = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -61,7 +61,7 @@ def einsum(
/,
*operands: _ArrayLikeUInt_co,
out: None = ...,
- dtype: Optional[_DTypeLikeUInt] = ...,
+ dtype: None | _DTypeLikeUInt = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -72,7 +72,7 @@ def einsum(
/,
*operands: _ArrayLikeInt_co,
out: None = ...,
- dtype: Optional[_DTypeLikeInt] = ...,
+ dtype: None | _DTypeLikeInt = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -83,7 +83,7 @@ def einsum(
/,
*operands: _ArrayLikeFloat_co,
out: None = ...,
- dtype: Optional[_DTypeLikeFloat] = ...,
+ dtype: None | _DTypeLikeFloat = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -94,7 +94,7 @@ def einsum(
/,
*operands: _ArrayLikeComplex_co,
out: None = ...,
- dtype: Optional[_DTypeLikeComplex] = ...,
+ dtype: None | _DTypeLikeComplex = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -105,7 +105,7 @@ def einsum(
/,
*operands: Any,
casting: _CastingUnsafe,
- dtype: Optional[_DTypeLikeComplex_co] = ...,
+ dtype: None | _DTypeLikeComplex_co = ...,
out: None = ...,
order: _OrderKACF = ...,
optimize: _OptimizeKind = ...,
@@ -116,7 +116,7 @@ def einsum(
/,
*operands: _ArrayLikeComplex_co,
out: _ArrayType,
- dtype: Optional[_DTypeLikeComplex_co] = ...,
+ dtype: None | _DTypeLikeComplex_co = ...,
order: _OrderKACF = ...,
casting: _CastingSafe = ...,
optimize: _OptimizeKind = ...,
@@ -128,7 +128,7 @@ def einsum(
*operands: Any,
out: _ArrayType,
casting: _CastingUnsafe,
- dtype: Optional[_DTypeLikeComplex_co] = ...,
+ dtype: None | _DTypeLikeComplex_co = ...,
order: _OrderKACF = ...,
optimize: _OptimizeKind = ...,
) -> _ArrayType: ...
diff --git a/numpy/core/fromnumeric.pyi b/numpy/core/fromnumeric.pyi
index 3cbe1d5c5..b09ed19da 100644
--- a/numpy/core/fromnumeric.pyi
+++ b/numpy/core/fromnumeric.pyi
@@ -1,5 +1,5 @@
import datetime as dt
-from typing import Optional, Union, Sequence, Tuple, Any, overload, TypeVar, Literal
+from typing import Union, Sequence, Tuple, Any, overload, TypeVar, Literal
from numpy import (
ndarray,
@@ -47,8 +47,8 @@ _Number = TypeVar("_Number", bound=number)
def take(
a: ArrayLike,
indices: _ArrayLikeInt_co,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | int = ...,
+ out: None | ndarray = ...,
mode: _ModeKind = ...,
) -> Any: ...
@@ -61,14 +61,14 @@ def reshape(
def choose(
a: _ArrayLikeInt_co,
choices: ArrayLike,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
mode: _ModeKind = ...,
) -> Any: ...
def repeat(
a: ArrayLike,
repeats: _ArrayLikeInt_co,
- axis: Optional[int] = ...,
+ axis: None | int = ...,
) -> ndarray: ...
def put(
@@ -92,7 +92,7 @@ def transpose(
def partition(
a: ArrayLike,
kth: _ArrayLikeInt_co,
- axis: Optional[int] = ...,
+ axis: None | int = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
@@ -100,22 +100,22 @@ def partition(
def argpartition(
a: ArrayLike,
kth: _ArrayLikeInt_co,
- axis: Optional[int] = ...,
+ axis: None | int = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> Any: ...
def sort(
a: ArrayLike,
- axis: Optional[int] = ...,
- kind: Optional[_SortKind] = ...,
+ axis: None | int = ...,
+ kind: None | _SortKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
def argsort(
a: ArrayLike,
- axis: Optional[int] = ...,
- kind: Optional[_SortKind] = ...,
+ axis: None | int = ...,
+ kind: None | _SortKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> ndarray: ...
@@ -123,15 +123,15 @@ def argsort(
def argmax(
a: ArrayLike,
axis: None = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
*,
keepdims: Literal[False] = ...,
) -> intp: ...
@overload
def argmax(
a: ArrayLike,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | int = ...,
+ out: None | ndarray = ...,
*,
keepdims: bool = ...,
) -> Any: ...
@@ -140,15 +140,15 @@ def argmax(
def argmin(
a: ArrayLike,
axis: None = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
*,
keepdims: Literal[False] = ...,
) -> intp: ...
@overload
def argmin(
a: ArrayLike,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | int = ...,
+ out: None | ndarray = ...,
*,
keepdims: bool = ...,
) -> Any: ...
@@ -158,14 +158,14 @@ def searchsorted(
a: ArrayLike,
v: _Scalar,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
+ sorter: None | _ArrayLikeInt_co = ..., # 1D int array
) -> intp: ...
@overload
def searchsorted(
a: ArrayLike,
v: ArrayLike,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
+ sorter: None | _ArrayLikeInt_co = ..., # 1D int array
) -> ndarray: ...
def resize(
@@ -176,12 +176,12 @@ def resize(
@overload
def squeeze(
a: _ScalarGeneric,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
) -> _ScalarGeneric: ...
@overload
def squeeze(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
) -> ndarray: ...
def diagonal(
@@ -197,7 +197,7 @@ def trace(
axis1: int = ...,
axis2: int = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
) -> Any: ...
def ravel(a: ArrayLike, order: _OrderKACF = ...) -> ndarray: ...
@@ -209,16 +209,16 @@ def shape(a: ArrayLike) -> _Shape: ...
def compress(
condition: ArrayLike, # 1D bool array
a: ArrayLike,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | int = ...,
+ out: None | ndarray = ...,
) -> ndarray: ...
@overload
def clip(
a: ArrayLike,
a_min: ArrayLike,
- a_max: Optional[ArrayLike],
- out: Optional[ndarray] = ...,
+ a_max: None | ArrayLike,
+ out: None | ndarray = ...,
**kwargs: Any,
) -> Any: ...
@overload
@@ -226,7 +226,7 @@ def clip(
a: ArrayLike,
a_min: None,
a_max: ArrayLike,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
**kwargs: Any,
) -> Any: ...
@@ -234,7 +234,7 @@ def sum(
a: ArrayLike,
axis: _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
where: _ArrayLikeBool_co = ...,
@@ -250,8 +250,8 @@ def all(
@overload
def all(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | _ShapeLike = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
) -> Any: ...
@@ -265,29 +265,29 @@ def any(
@overload
def any(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | _ShapeLike = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
) -> Any: ...
def cumsum(
a: ArrayLike,
- axis: Optional[int] = ...,
+ axis: None | int = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
) -> ndarray: ...
def ptp(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | _ShapeLike = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
) -> Any: ...
def amax(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | _ShapeLike = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
where: _ArrayLikeBool_co = ...,
@@ -295,8 +295,8 @@ def amax(
def amin(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
+ axis: None | _ShapeLike = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
where: _ArrayLikeBool_co = ...,
@@ -311,9 +311,9 @@ def amin(
# `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
def prod(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
initial: _NumberLike_co = ...,
where: _ArrayLikeBool_co = ...,
@@ -321,43 +321,43 @@ def prod(
def cumprod(
a: ArrayLike,
- axis: Optional[int] = ...,
+ axis: None | int = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
) -> ndarray: ...
def ndim(a: ArrayLike) -> int: ...
-def size(a: ArrayLike, axis: Optional[int] = ...) -> int: ...
+def size(a: ArrayLike, axis: None | int = ...) -> int: ...
def around(
a: ArrayLike,
decimals: int = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
) -> Any: ...
def mean(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
keepdims: bool = ...,
) -> Any: ...
def std(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
ddof: int = ...,
keepdims: bool = ...,
) -> Any: ...
def var(
a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[ndarray] = ...,
+ out: None | ndarray = ...,
ddof: int = ...,
keepdims: bool = ...,
) -> Any: ...
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
index a9f68e181..62b4b8bfc 100644
--- a/numpy/core/multiarray.pyi
+++ b/numpy/core/multiarray.pyi
@@ -7,7 +7,6 @@ from typing import (
Any,
Callable,
Iterable,
- Optional,
overload,
TypeVar,
List,
@@ -138,7 +137,7 @@ def empty_like(
dtype: None = ...,
order: _OrderKACF = ...,
subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
+ shape: None | _ShapeLike = ...,
) -> _ArrayType: ...
@overload
def empty_like(
@@ -146,7 +145,7 @@ def empty_like(
dtype: None = ...,
order: _OrderKACF = ...,
subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
+ shape: None | _ShapeLike = ...,
) -> NDArray[_SCT]: ...
@overload
def empty_like(
@@ -154,7 +153,7 @@ def empty_like(
dtype: None = ...,
order: _OrderKACF = ...,
subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
+ shape: None | _ShapeLike = ...,
) -> NDArray[Any]: ...
@overload
def empty_like(
@@ -162,7 +161,7 @@ def empty_like(
dtype: _DTypeLike[_SCT],
order: _OrderKACF = ...,
subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
+ shape: None | _ShapeLike = ...,
) -> NDArray[_SCT]: ...
@overload
def empty_like(
@@ -170,7 +169,7 @@ def empty_like(
dtype: DTypeLike,
order: _OrderKACF = ...,
subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
+ shape: None | _ShapeLike = ...,
) -> NDArray[Any]: ...
@overload
@@ -311,51 +310,51 @@ def ravel_multi_index(
def concatenate( # type: ignore[misc]
arrays: _ArrayLike[_SCT],
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
*,
dtype: None = ...,
- casting: Optional[_CastingKind] = ...
+ casting: None | _CastingKind = ...
) -> NDArray[_SCT]: ...
@overload
def concatenate( # type: ignore[misc]
arrays: ArrayLike,
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
*,
dtype: None = ...,
- casting: Optional[_CastingKind] = ...
+ casting: None | _CastingKind = ...
) -> NDArray[Any]: ...
@overload
def concatenate( # type: ignore[misc]
arrays: ArrayLike,
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
*,
dtype: _DTypeLike[_SCT],
- casting: Optional[_CastingKind] = ...
+ casting: None | _CastingKind = ...
) -> NDArray[_SCT]: ...
@overload
def concatenate( # type: ignore[misc]
arrays: ArrayLike,
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: None = ...,
*,
dtype: DTypeLike,
- casting: Optional[_CastingKind] = ...
+ casting: None | _CastingKind = ...
) -> NDArray[Any]: ...
@overload
def concatenate(
arrays: ArrayLike,
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
out: _ArrayType = ...,
*,
dtype: DTypeLike = ...,
- casting: Optional[_CastingKind] = ...
+ casting: None | _CastingKind = ...
) -> _ArrayType: ...
def inner(
@@ -379,13 +378,13 @@ def where(
def lexsort(
keys: ArrayLike,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
) -> Any: ...
def can_cast(
from_: Union[ArrayLike, DTypeLike],
to: DTypeLike,
- casting: Optional[_CastingKind] = ...,
+ casting: None | _CastingKind = ...,
) -> bool: ...
def min_scalar_type(
@@ -421,15 +420,15 @@ def vdot(a: Any, b: _ArrayLikeObject_co, /) -> Any: ...
def bincount(
x: ArrayLike,
/,
- weights: Optional[ArrayLike] = ...,
+ weights: None | ArrayLike = ...,
minlength: SupportsIndex = ...,
) -> NDArray[intp]: ...
def copyto(
dst: NDArray[Any],
src: ArrayLike,
- casting: Optional[_CastingKind] = ...,
- where: Optional[_ArrayLikeBool_co] = ...,
+ casting: None | _CastingKind = ...,
+ where: None | _ArrayLikeBool_co = ...,
) -> None: ...
def putmask(
@@ -441,15 +440,15 @@ def putmask(
def packbits(
a: _ArrayLikeInt_co,
/,
- axis: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
bitorder: L["big", "little"] = ...,
) -> NDArray[uint8]: ...
def unpackbits(
a: _ArrayLike[uint8],
/,
- axis: Optional[SupportsIndex] = ...,
- count: Optional[SupportsIndex] = ...,
+ axis: None | SupportsIndex = ...,
+ count: None | SupportsIndex = ...,
bitorder: L["big", "little"] = ...,
) -> NDArray[uint8]: ...
@@ -457,14 +456,14 @@ def shares_memory(
a: object,
b: object,
/,
- max_work: Optional[int] = ...,
+ max_work: None | int = ...,
) -> bool: ...
def may_share_memory(
a: object,
b: object,
/,
- max_work: Optional[int] = ...,
+ max_work: None | int = ...,
) -> bool: ...
@overload
diff --git a/numpy/ctypeslib.pyi b/numpy/ctypeslib.pyi
index d2a87fd03..62aa374b6 100644
--- a/numpy/ctypeslib.pyi
+++ b/numpy/ctypeslib.pyi
@@ -13,7 +13,6 @@ from typing import (
TypeVar,
Type,
Generic,
- Optional,
overload,
Iterable,
ClassVar,
@@ -77,7 +76,7 @@ from numpy.typing import (
# TODO: Add a proper `_Shape` bound once we've got variadic typevars
_DType = TypeVar("_DType", bound=dtype[Any])
-_DTypeOptional = TypeVar("_DTypeOptional", bound=Optional[dtype[Any]])
+_DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any])
_SCT = TypeVar("_SCT", bound=generic)
_DTypeLike = Union[
diff --git a/numpy/lib/utils.pyi b/numpy/lib/utils.pyi
index f0a8797ad..f42ba9efb 100644
--- a/numpy/lib/utils.pyi
+++ b/numpy/lib/utils.pyi
@@ -4,7 +4,6 @@ from typing import (
Callable,
List,
Mapping,
- Optional,
overload,
Sequence,
Tuple,
@@ -31,14 +30,14 @@ class _SupportsWrite(Protocol[_T_contra]):
__all__: List[str]
class _Deprecate:
- old_name: Optional[str]
- new_name: Optional[str]
- message: Optional[str]
+ old_name: None | str
+ new_name: None | str
+ message: None | str
def __init__(
self,
- old_name: Optional[str] = ...,
- new_name: Optional[str] = ...,
- message: Optional[str] = ...,
+ old_name: None | str = ...,
+ new_name: None | str = ...,
+ message: None | str = ...,
) -> None: ...
# NOTE: `__call__` can in principle take arbitrary `*args` and `**kwargs`,
# even though they aren't used for anything
@@ -49,20 +48,20 @@ def get_include() -> str: ...
@overload
def deprecate(
*,
- old_name: Optional[str] = ...,
- new_name: Optional[str] = ...,
- message: Optional[str] = ...,
+ old_name: None | str = ...,
+ new_name: None | str = ...,
+ message: None | str = ...,
) -> _Deprecate: ...
@overload
def deprecate(
func: _FuncType,
/,
- old_name: Optional[str] = ...,
- new_name: Optional[str] = ...,
- message: Optional[str] = ...,
+ old_name: None | str = ...,
+ new_name: None | str = ...,
+ message: None | str = ...,
) -> _FuncType: ...
-def deprecate_with_doc(msg: Optional[str]) -> _Deprecate: ...
+def deprecate_with_doc(msg: None | str) -> _Deprecate: ...
# NOTE: In practice `byte_bounds` can (potentially) take any object
# implementing the `__array_interface__` protocol. The caveat is
@@ -70,18 +69,18 @@ def deprecate_with_doc(msg: Optional[str]) -> _Deprecate: ...
# `byte_bounds`. This concerns `"strides"` and `"data"`.
def byte_bounds(a: Union[generic, ndarray[Any, Any]]) -> Tuple[int, int]: ...
-def who(vardict: Optional[Mapping[str, ndarray[Any, Any]]] = ...) -> None: ...
+def who(vardict: None | Mapping[str, ndarray[Any, Any]] = ...) -> None: ...
def info(
object: object = ...,
maxwidth: int = ...,
- output: Optional[_SupportsWrite[str]] = ...,
+ output: None | _SupportsWrite[str] = ...,
toplevel: str = ...,
) -> None: ...
def source(
object: object,
- output: Optional[_SupportsWrite[str]] = ...,
+ output: None | _SupportsWrite[str] = ...,
) -> None: ...
def lookfor(
@@ -89,7 +88,7 @@ def lookfor(
module: Union[None, str, Sequence[str]] = ...,
import_modules: bool = ...,
regenerate: bool = ...,
- output: Optional[_SupportsWrite[str]] =...,
+ output: None | _SupportsWrite[str] =...,
) -> None: ...
def safe_eval(source: Union[str, AST]) -> Any: ...
diff --git a/numpy/random/_generator.pyi b/numpy/random/_generator.pyi
index c574bef9a..11499501e 100644
--- a/numpy/random/_generator.pyi
+++ b/numpy/random/_generator.pyi
@@ -1,4 +1,4 @@
-from typing import Any, Callable, Dict, Optional, Tuple, Type, Union, overload, TypeVar, Literal
+from typing import Any, Callable, Dict, Tuple, Type, Union, overload, TypeVar, Literal
from numpy import (
bool_,
@@ -95,14 +95,14 @@ class Generator:
self,
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat32 = ...,
- out: Optional[ndarray[Any, dtype[float32]]] = ...,
+ out: None | ndarray[Any, dtype[float32]] = ...,
) -> ndarray[Any, dtype[float32]]: ...
@overload
def standard_normal( # type: ignore[misc]
self,
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat64 = ...,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def permutation(self, x: int, axis: int = ...) -> ndarray[Any, dtype[int64]]: ...
@@ -133,7 +133,7 @@ class Generator:
size: _ShapeLike = ...,
*,
method: Literal["zig", "inv"] = ...,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_exponential(
@@ -141,7 +141,7 @@ class Generator:
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat32 = ...,
method: Literal["zig", "inv"] = ...,
- out: Optional[ndarray[Any, dtype[float32]]] = ...,
+ out: None | ndarray[Any, dtype[float32]] = ...,
) -> ndarray[Any, dtype[float32]]: ...
@overload
def standard_exponential(
@@ -149,7 +149,7 @@ class Generator:
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat64 = ...,
method: Literal["zig", "inv"] = ...,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def random( # type: ignore[misc]
@@ -169,45 +169,45 @@ class Generator:
self,
size: _ShapeLike = ...,
*,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def random(
self,
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat32 = ...,
- out: Optional[ndarray[Any, dtype[float32]]] = ...,
+ out: None | ndarray[Any, dtype[float32]] = ...,
) -> ndarray[Any, dtype[float32]]: ...
@overload
def random(
self,
size: _ShapeLike = ...,
dtype: _DTypeLikeFloat64 = ...,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def beta(self, a: float, b: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def beta(
- self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def exponential(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@overload
def exponential(
- self, scale: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def integers( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
) -> int: ...
@overload
def integers( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
size: None = ...,
dtype: _DTypeLikeBool = ...,
endpoint: bool = ...,
@@ -216,7 +216,7 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
size: None = ...,
dtype: Union[_DTypeLikeInt, _DTypeLikeUInt] = ...,
endpoint: bool = ...,
@@ -225,15 +225,15 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[int64]]: ...
@overload
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: _DTypeLikeBool = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[bool_]]: ...
@@ -241,8 +241,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int8], Type[int8], _Int8Codes, _SupportsDType[dtype[int8]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int8]]: ...
@@ -250,8 +250,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int16], Type[int16], _Int16Codes, _SupportsDType[dtype[int16]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int16]]: ...
@@ -259,8 +259,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int32], Type[int32], _Int32Codes, _SupportsDType[dtype[int32]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[Union[int32]]]: ...
@@ -268,19 +268,17 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
- dtype: Optional[
- Union[dtype[int64], Type[int64], _Int64Codes, _SupportsDType[dtype[int64]]]
- ] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
+ dtype: None | Union[dtype[int64], Type[int64], _Int64Codes, _SupportsDType[dtype[int64]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[int64]]: ...
@overload
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[uint8], Type[uint8], _UInt8Codes, _SupportsDType[dtype[uint8]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint8]]: ...
@@ -288,8 +286,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint16], Type[uint16], _UInt16Codes, _SupportsDType[dtype[uint16]]
] = ...,
@@ -299,8 +297,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint32], Type[uint32], _UInt32Codes, _SupportsDType[dtype[uint32]]
] = ...,
@@ -310,8 +308,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint64], Type[uint64], _UInt64Codes, _SupportsDType[dtype[uint64]]
] = ...,
@@ -321,8 +319,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[int_], Type[int], Type[int_], _IntCodes, _SupportsDType[dtype[int_]]
] = ...,
@@ -332,8 +330,8 @@ class Generator:
def integers( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[uint], Type[uint], _UIntCodes, _SupportsDType[dtype[uint]]] = ...,
endpoint: bool = ...,
) -> ndarray[Any, dtype[uint]]: ...
@@ -344,7 +342,7 @@ class Generator:
a: int,
size: None = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
axis: int = ...,
shuffle: bool = ...,
) -> int: ...
@@ -354,7 +352,7 @@ class Generator:
a: int,
size: _ShapeLike = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
axis: int = ...,
shuffle: bool = ...,
) -> ndarray[Any, dtype[int64]]: ...
@@ -364,7 +362,7 @@ class Generator:
a: ArrayLike,
size: None = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
axis: int = ...,
shuffle: bool = ...,
) -> Any: ...
@@ -374,7 +372,7 @@ class Generator:
a: ArrayLike,
size: _ShapeLike = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
axis: int = ...,
shuffle: bool = ...,
) -> ndarray[Any, Any]: ...
@@ -385,7 +383,7 @@ class Generator:
self,
low: _ArrayLikeFloat_co = ...,
high: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def normal(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -394,7 +392,7 @@ class Generator:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_gamma( # type: ignore[misc]
@@ -408,7 +406,7 @@ class Generator:
def standard_gamma(
self,
shape: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_gamma(
@@ -421,17 +419,17 @@ class Generator:
def standard_gamma(
self,
shape: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
dtype: _DTypeLikeFloat32 = ...,
- out: Optional[ndarray[Any, dtype[float32]]] = ...,
+ out: None | ndarray[Any, dtype[float32]] = ...,
) -> ndarray[Any, dtype[float32]]: ...
@overload
def standard_gamma(
self,
shape: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
dtype: _DTypeLikeFloat64 = ...,
- out: Optional[ndarray[Any, dtype[float64]]] = ...,
+ out: None | ndarray[Any, dtype[float64]] = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def gamma(self, shape: float, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -440,13 +438,13 @@ class Generator:
self,
shape: _ArrayLikeFloat_co,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def f(self, dfnum: float, dfden: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def f(
- self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def noncentral_f(self, dfnum: float, dfden: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -456,19 +454,19 @@ class Generator:
dfnum: _ArrayLikeFloat_co,
dfden: _ArrayLikeFloat_co,
nonc: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def chisquare(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def chisquare(
- self, df: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def noncentral_chisquare(self, df: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def noncentral_chisquare(
- self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_t(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -484,25 +482,25 @@ class Generator:
def vonmises(self, mu: float, kappa: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def vonmises(
- self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def pareto(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def pareto(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def weibull(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def weibull(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def power(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def power(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
@@ -515,7 +513,7 @@ class Generator:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def gumbel(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -524,7 +522,7 @@ class Generator:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def logistic(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -533,7 +531,7 @@ class Generator:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def lognormal(self, mean: float = ..., sigma: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -542,19 +540,19 @@ class Generator:
self,
mean: _ArrayLikeFloat_co = ...,
sigma: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def rayleigh(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@overload
def rayleigh(
- self, scale: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def wald(self, mean: float, scale: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def wald(
- self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def triangular(self, left: float, mode: float, right: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -564,37 +562,37 @@ class Generator:
left: _ArrayLikeFloat_co,
mode: _ArrayLikeFloat_co,
right: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def binomial(self, n: int, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def binomial(
- self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
@overload
def negative_binomial(self, n: float, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def negative_binomial(
- self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
@overload
def poisson(self, lam: float = ..., size: None = ...) -> int: ... # type: ignore[misc]
@overload
def poisson(
- self, lam: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
@overload
def zipf(self, a: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def zipf(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
@overload
def geometric(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def geometric(
- self, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
@overload
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
@@ -604,19 +602,19 @@ class Generator:
ngood: _ArrayLikeInt_co,
nbad: _ArrayLikeInt_co,
nsample: _ArrayLikeInt_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[int64]]: ...
@overload
def logseries(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def logseries(
- self, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
def multivariate_normal(
self,
mean: _ArrayLikeFloat_co,
cov: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
check_valid: Literal["warn", "raise", "ignore"] = ...,
tol: float = ...,
*,
@@ -625,20 +623,20 @@ class Generator:
def multinomial(
self, n: _ArrayLikeInt_co,
pvals: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...
+ size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int64]]: ...
def multivariate_hypergeometric(
self,
colors: _ArrayLikeInt_co,
nsample: int,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
method: Literal["marginals", "count"] = ...,
) -> ndarray[Any, dtype[int64]]: ...
def dirichlet(
- self, alpha: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
def permuted(
- self, x: ArrayLike, *, axis: Optional[int] = ..., out: Optional[ndarray[Any, Any]] = ...
+ self, x: ArrayLike, *, axis: None | int = ..., out: None | ndarray[Any, Any] = ...
) -> ndarray[Any, Any]: ...
def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ...
diff --git a/numpy/random/bit_generator.pyi b/numpy/random/bit_generator.pyi
index fa2f1ab12..5d8b12651 100644
--- a/numpy/random/bit_generator.pyi
+++ b/numpy/random/bit_generator.pyi
@@ -7,7 +7,6 @@ from typing import (
List,
Mapping,
NamedTuple,
- Optional,
Sequence,
Tuple,
Type,
@@ -108,7 +107,7 @@ class BitGenerator(abc.ABC):
@overload
def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> ndarray[Any, dtype[uint64]]: ... # type: ignore[misc]
@overload
- def random_raw(self, size: Optional[_ShapeLike] = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc]
+ def random_raw(self, size: None | _ShapeLike = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc]
def _benchmark(self, cnt: int, method: str = ...) -> None: ...
@property
def ctypes(self) -> _Interface: ...
diff --git a/numpy/random/mtrand.pyi b/numpy/random/mtrand.pyi
index cbe87a299..0769ff19e 100644
--- a/numpy/random/mtrand.pyi
+++ b/numpy/random/mtrand.pyi
@@ -1,4 +1,4 @@
-from typing import Any, Callable, Dict, Optional, Tuple, Type, Union, overload, Literal
+from typing import Any, Callable, Dict, Tuple, Type, Union, overload, Literal
from numpy import (
bool_,
@@ -68,7 +68,7 @@ class RandomState:
def __getstate__(self) -> Dict[str, Any]: ...
def __setstate__(self, state: Dict[str, Any]) -> None: ...
def __reduce__(self) -> Tuple[Callable[[str], RandomState], Tuple[str], Dict[str, Any]]: ...
- def seed(self, seed: Optional[_ArrayLikeFloat_co] = ...) -> None: ...
+ def seed(self, seed: None | _ArrayLikeFloat_co = ...) -> None: ...
@overload
def get_state(self, legacy: Literal[False] = ...) -> Dict[str, Any]: ...
@overload
@@ -90,13 +90,13 @@ class RandomState:
def beta(self, a: float, b: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def beta(
- self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def exponential(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@overload
def exponential(
- self, scale: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_exponential(self, size: None = ...) -> float: ... # type: ignore[misc]
@@ -110,13 +110,13 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
) -> int: ...
@overload
def randint( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
size: None = ...,
dtype: _DTypeLikeBool = ...,
) -> bool: ...
@@ -124,7 +124,7 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: int,
- high: Optional[int] = ...,
+ high: None | int = ...,
size: None = ...,
dtype: Union[_DTypeLikeInt, _DTypeLikeUInt] = ...,
) -> int: ...
@@ -132,65 +132,63 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: _DTypeLikeBool = ...,
) -> ndarray[Any, dtype[bool_]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int8], Type[int8], _Int8Codes, _SupportsDType[dtype[int8]]] = ...,
) -> ndarray[Any, dtype[int8]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int16], Type[int16], _Int16Codes, _SupportsDType[dtype[int16]]] = ...,
) -> ndarray[Any, dtype[int16]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[int32], Type[int32], _Int32Codes, _SupportsDType[dtype[int32]]] = ...,
) -> ndarray[Any, dtype[Union[int32]]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
- dtype: Optional[
- Union[dtype[int64], Type[int64], _Int64Codes, _SupportsDType[dtype[int64]]]
- ] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
+ dtype: None | dtype[int64] | Type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
) -> ndarray[Any, dtype[int64]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[uint8], Type[uint8], _UInt8Codes, _SupportsDType[dtype[uint8]]] = ...,
) -> ndarray[Any, dtype[uint8]]: ...
@overload
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint16], Type[uint16], _UInt16Codes, _SupportsDType[dtype[uint16]]
] = ...,
@@ -199,8 +197,8 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint32], Type[uint32], _UInt32Codes, _SupportsDType[dtype[uint32]]
] = ...,
@@ -209,8 +207,8 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[uint64], Type[uint64], _UInt64Codes, _SupportsDType[dtype[uint64]]
] = ...,
@@ -219,8 +217,8 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[
dtype[int_], Type[int], Type[int_], _IntCodes, _SupportsDType[dtype[int_]]
] = ...,
@@ -229,8 +227,8 @@ class RandomState:
def randint( # type: ignore[misc]
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
dtype: Union[dtype[uint], Type[uint], _UIntCodes, _SupportsDType[dtype[uint]]] = ...,
) -> ndarray[Any, dtype[uint]]: ...
def bytes(self, length: int) -> bytes: ...
@@ -240,7 +238,7 @@ class RandomState:
a: int,
size: None = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
) -> int: ...
@overload
def choice(
@@ -248,7 +246,7 @@ class RandomState:
a: int,
size: _ShapeLike = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
def choice(
@@ -256,7 +254,7 @@ class RandomState:
a: ArrayLike,
size: None = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
) -> Any: ...
@overload
def choice(
@@ -264,7 +262,7 @@ class RandomState:
a: ArrayLike,
size: _ShapeLike = ...,
replace: bool = ...,
- p: Optional[_ArrayLikeFloat_co] = ...,
+ p: None | _ArrayLikeFloat_co = ...,
) -> ndarray[Any, Any]: ...
@overload
def uniform(self, low: float = ..., high: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -273,7 +271,7 @@ class RandomState:
self,
low: _ArrayLikeFloat_co = ...,
high: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def rand(self) -> float: ...
@@ -284,13 +282,13 @@ class RandomState:
@overload
def randn(self, *args: int) -> ndarray[Any, dtype[float64]]: ...
@overload
- def random_integers(self, low: int, high: Optional[int] = ..., size: None = ...) -> int: ... # type: ignore[misc]
+ def random_integers(self, low: int, high: None | int = ..., size: None = ...) -> int: ... # type: ignore[misc]
@overload
def random_integers(
self,
low: _ArrayLikeInt_co,
- high: Optional[_ArrayLikeInt_co] = ...,
- size: Optional[_ShapeLike] = ...,
+ high: None | _ArrayLikeInt_co = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
def standard_normal(self, size: None = ...) -> float: ... # type: ignore[misc]
@@ -305,7 +303,7 @@ class RandomState:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_gamma( # type: ignore[misc]
@@ -317,7 +315,7 @@ class RandomState:
def standard_gamma(
self,
shape: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def gamma(self, shape: float, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -326,13 +324,13 @@ class RandomState:
self,
shape: _ArrayLikeFloat_co,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def f(self, dfnum: float, dfden: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def f(
- self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def noncentral_f(self, dfnum: float, dfden: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -342,19 +340,19 @@ class RandomState:
dfnum: _ArrayLikeFloat_co,
dfden: _ArrayLikeFloat_co,
nonc: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def chisquare(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def chisquare(
- self, df: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def noncentral_chisquare(self, df: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def noncentral_chisquare(
- self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_t(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -370,25 +368,25 @@ class RandomState:
def vonmises(self, mu: float, kappa: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def vonmises(
- self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def pareto(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def pareto(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def weibull(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def weibull(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def power(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def power(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
@@ -401,7 +399,7 @@ class RandomState:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def gumbel(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -410,7 +408,7 @@ class RandomState:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def logistic(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -419,7 +417,7 @@ class RandomState:
self,
loc: _ArrayLikeFloat_co = ...,
scale: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def lognormal(self, mean: float = ..., sigma: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@@ -428,19 +426,19 @@ class RandomState:
self,
mean: _ArrayLikeFloat_co = ...,
sigma: _ArrayLikeFloat_co = ...,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def rayleigh(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
@overload
def rayleigh(
- self, scale: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def wald(self, mean: float, scale: float, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def wald(
- self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
@overload
def triangular(self, left: float, mode: float, right: float, size: None = ...) -> float: ... # type: ignore[misc]
@@ -450,37 +448,37 @@ class RandomState:
left: _ArrayLikeFloat_co,
mode: _ArrayLikeFloat_co,
right: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[float64]]: ...
@overload
def binomial(self, n: int, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def binomial(
- self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
@overload
def negative_binomial(self, n: float, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def negative_binomial(
- self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
@overload
def poisson(self, lam: float = ..., size: None = ...) -> int: ... # type: ignore[misc]
@overload
def poisson(
- self, lam: _ArrayLikeFloat_co = ..., size: Optional[_ShapeLike] = ...
+ self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
@overload
def zipf(self, a: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def zipf(
- self, a: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
@overload
def geometric(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def geometric(
- self, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
@overload
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
@@ -490,27 +488,27 @@ class RandomState:
ngood: _ArrayLikeInt_co,
nbad: _ArrayLikeInt_co,
nsample: _ArrayLikeInt_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
) -> ndarray[Any, dtype[int_]]: ...
@overload
def logseries(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
@overload
def logseries(
- self, p: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
def multivariate_normal(
self,
mean: _ArrayLikeFloat_co,
cov: _ArrayLikeFloat_co,
- size: Optional[_ShapeLike] = ...,
+ size: None | _ShapeLike = ...,
check_valid: Literal["warn", "raise", "ignore"] = ...,
tol: float = ...,
) -> ndarray[Any, dtype[float64]]: ...
def multinomial(
- self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, n: _ArrayLikeInt_co, pvals: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[int_]]: ...
def dirichlet(
- self, alpha: _ArrayLikeFloat_co, size: Optional[_ShapeLike] = ...
+ self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
) -> ndarray[Any, dtype[float64]]: ...
def shuffle(self, x: ArrayLike) -> None: ...
@overload
diff --git a/numpy/typing/tests/data/pass/array_like.py b/numpy/typing/tests/data/pass/array_like.py
index 5bd2fda20..4e9f8dded 100644
--- a/numpy/typing/tests/data/pass/array_like.py
+++ b/numpy/typing/tests/data/pass/array_like.py
@@ -1,4 +1,6 @@
-from typing import Any, Optional
+from __future__ import annotations
+
+from typing import Any
import numpy as np
from numpy.typing import ArrayLike, _SupportsArray
@@ -18,7 +20,7 @@ x12: ArrayLike = memoryview(b'foo')
class A:
- def __array__(self, dtype: Optional[np.dtype] = None) -> np.ndarray:
+ def __array__(self, dtype: None | np.dtype[Any] = None) -> np.ndarray:
return np.array([1, 2, 3])