summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-05-24 15:04:06 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-05-27 18:23:57 +0200
commit757eb4abd1b6823d4d7933c9ad0c75160750833b (patch)
treee3941817371ebede02e872faab771205c89dbf21
parent44e72e771bff812c00e48bd6c94d90f9f46a7254 (diff)
downloadnumpy-757eb4abd1b6823d4d7933c9ad0c75160750833b.tar.gz
STY: Use the PEP 604 pipe operator over `Optional` and `Union`
PEP 604 -- Allow writing union types as X | Y
-rw-r--r--numpy/typing/__init__.py4
-rw-r--r--numpy/typing/_callable.py92
-rw-r--r--numpy/typing/_ufunc.pyi70
-rw-r--r--numpy/typing/mypy_plugin.py4
4 files changed, 84 insertions, 86 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py
index f27e6ff1a..04d34f0c7 100644
--- a/numpy/typing/__init__.py
+++ b/numpy/typing/__init__.py
@@ -212,14 +212,14 @@ class NBitBase:
.. code-block:: python
>>> from __future__ import annotations
- >>> from typing import TypeVar, Union, TYPE_CHECKING
+ >>> from typing import TypeVar, TYPE_CHECKING
>>> 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
>>> a = np.float16()
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py
index 84fc2adb9..54f9b1425 100644
--- a/numpy/typing/_callable.py
+++ b/numpy/typing/_callable.py
@@ -102,7 +102,7 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
class _BoolTrueDiv(Protocol):
@overload
- def __call__(self, __other: Union[float, _IntLike_co]) -> float64: ...
+ def __call__(self, __other: float | _IntLike_co) -> float64: ...
@overload
def __call__(self, __other: complex) -> complex128: ...
@overload
@@ -126,7 +126,7 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
@overload # platform dependent
def __call__(self, __other: int) -> _2Tuple[int_]: ...
@overload
- def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
+ def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(self, __other: _IntType) -> _2Tuple[_IntType]: ...
@overload
@@ -144,15 +144,15 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
- ) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
+ ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
- def __call__(self, __other: integer[_NBit2]) -> floating[Union[_NBit1, _NBit2]]: ...
+ def __call__(self, __other: integer[_NBit2]) -> floating[_NBit1 | _NBit2]: ...
class _UnsignedIntOp(Protocol[_NBit1]):
# NOTE: `uint64 + signedinteger -> float64`
@@ -160,18 +160,18 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ...
@overload
def __call__(
- self, __other: Union[int, signedinteger[Any]]
+ self, __other: int | signedinteger[Any]
) -> Any: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
- ) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
+ ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
- ) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> unsignedinteger[_NBit1 | _NBit2]: ...
class _UnsignedIntBitOp(Protocol[_NBit1]):
@overload
@@ -183,135 +183,135 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
- ) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> unsignedinteger[_NBit1 | _NBit2]: ...
class _UnsignedIntMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ...
@overload
def __call__(
- self, __other: Union[int, signedinteger[Any]]
+ self, __other: int | signedinteger[Any]
) -> Any: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
- ) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> unsignedinteger[_NBit1 | _NBit2]: ...
class _UnsignedIntDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ...
@overload
def __call__(
- self, __other: Union[int, signedinteger[Any]]
+ self, __other: int | signedinteger[Any]
) -> _2Tuple[Any]: ...
@overload
- def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
+ def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
- ) -> _2Tuple[unsignedinteger[Union[_NBit1, _NBit2]]]: ...
+ ) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ...
class _SignedIntOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
- ) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
+ ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
- ) -> signedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> signedinteger[_NBit1 | _NBit2]: ...
class _SignedIntBitOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
- ) -> signedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> signedinteger[_NBit1 | _NBit2]: ...
class _SignedIntMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
- ) -> signedinteger[Union[_NBit1, _NBit2]]: ...
+ ) -> signedinteger[_NBit1 | _NBit2]: ...
class _SignedIntDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ...
@overload
- def __call__(self, __other: int) -> _2Tuple[signedinteger[Union[_NBit1, _NBitInt]]]: ...
+ def __call__(self, __other: int) -> _2Tuple[signedinteger[_NBit1 | _NBitInt]]: ...
@overload
- def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
+ def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
- ) -> _2Tuple[signedinteger[Union[_NBit1, _NBit2]]]: ...
+ ) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ...
class _FloatOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
- ) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
+ ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
- self, __other: Union[integer[_NBit2], floating[_NBit2]]
- ) -> floating[Union[_NBit1, _NBit2]]: ...
+ self, __other: integer[_NBit2] | floating[_NBit2]
+ ) -> floating[_NBit1 | _NBit2]: ...
class _FloatMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
- def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
- def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
+ def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
- self, __other: Union[integer[_NBit2], floating[_NBit2]]
- ) -> floating[Union[_NBit1, _NBit2]]: ...
+ self, __other: integer[_NBit2] | floating[_NBit2]
+ ) -> floating[_NBit1 | _NBit2]: ...
class _FloatDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[floating[_NBit1]]: ...
@overload
- def __call__(self, __other: int) -> _2Tuple[floating[Union[_NBit1, _NBitInt]]]: ...
+ def __call__(self, __other: int) -> _2Tuple[floating[_NBit1 | _NBitInt]]: ...
@overload
- def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
+ def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
- self, __other: Union[integer[_NBit2], floating[_NBit2]]
- ) -> _2Tuple[floating[Union[_NBit1, _NBit2]]]: ...
+ self, __other: integer[_NBit2] | floating[_NBit2]
+ ) -> _2Tuple[floating[_NBit1 | _NBit2]]: ...
class _ComplexOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> complexfloating[_NBit1, _NBit1]: ...
@overload
- def __call__(self, __other: int) -> complexfloating[Union[_NBit1, _NBitInt], Union[_NBit1, _NBitInt]]: ...
+ def __call__(self, __other: int) -> complexfloating[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ...
@overload
def __call__(
- self, __other: Union[float, complex]
- ) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
+ self, __other: complex
+ ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self,
@@ -320,7 +320,7 @@ if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS:
floating[_NBit2],
complexfloating[_NBit2, _NBit2],
]
- ) -> complexfloating[Union[_NBit1, _NBit2], Union[_NBit1, _NBit2]]: ...
+ ) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ...
class _NumberOp(Protocol):
def __call__(self, __other: _NumberLike_co) -> Any: ...
diff --git a/numpy/typing/_ufunc.pyi b/numpy/typing/_ufunc.pyi
index b3b9fa95e..f4fead504 100644
--- a/numpy/typing/_ufunc.pyi
+++ b/numpy/typing/_ufunc.pyi
@@ -11,11 +11,9 @@ from typing import (
Any,
Generic,
List,
- Optional,
overload,
Tuple,
TypeVar,
- Union,
)
from numpy import ufunc, _Casting, _OrderKACF
@@ -82,26 +80,26 @@ class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__x1: _ScalarLike_co,
out: None = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _2Tuple[Optional[str]]] = ...,
+ signature: str | _2Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> Any: ...
@overload
def __call__(
self,
__x1: ArrayLike,
- out: Union[None, NDArray[Any], Tuple[NDArray[Any]]] = ...,
+ out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _2Tuple[Optional[str]]] = ...,
+ signature: str | _2Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> NDArray[Any]: ...
@@ -134,12 +132,12 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__x2: _ScalarLike_co,
out: None = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> Any: ...
@overload
@@ -147,14 +145,14 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
self,
__x1: ArrayLike,
__x2: ArrayLike,
- out: Union[None, NDArray[Any], Tuple[NDArray[Any]]] = ...,
+ out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> NDArray[Any]: ...
@@ -168,9 +166,9 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
def reduce(
self,
array: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
+ axis: None | _ShapeLike = ...,
dtype: DTypeLike = ...,
- out: Optional[NDArray[Any]] = ...,
+ out: None | NDArray[Any] = ...,
keepdims: bool = ...,
initial: Any = ...,
where: _ArrayLikeBool_co = ...,
@@ -181,7 +179,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
array: ArrayLike,
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
- out: Optional[NDArray[Any]] = ...,
+ out: None | NDArray[Any] = ...,
) -> NDArray[Any]: ...
def reduceat(
@@ -190,7 +188,7 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
indices: _ArrayLikeInt_co,
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
- out: Optional[NDArray[Any]] = ...,
+ out: None | NDArray[Any] = ...,
) -> NDArray[Any]: ...
# Expand `**kwargs` into explicit keyword-only arguments
@@ -201,12 +199,12 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__B: _ScalarLike_co,
*,
out: None = ...,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> Any: ...
@overload
@@ -215,13 +213,13 @@ class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
__A: ArrayLike,
__B: ArrayLike,
*,
- out: Union[None, NDArray[Any], Tuple[NDArray[Any]]] = ...,
- where: Optional[_ArrayLikeBool_co] = ...,
+ out: None | NDArray[Any] | Tuple[NDArray[Any]] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> NDArray[Any]: ...
@@ -258,28 +256,28 @@ class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
__out1: None = ...,
__out2: None = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> _2Tuple[Any]: ...
@overload
def __call__(
self,
__x1: ArrayLike,
- __out1: Optional[NDArray[Any]] = ...,
- __out2: Optional[NDArray[Any]] = ...,
+ __out1: None | NDArray[Any] = ...,
+ __out2: None | NDArray[Any] = ...,
*,
out: _2Tuple[NDArray[Any]] = ...,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> _2Tuple[NDArray[Any]]: ...
@@ -317,12 +315,12 @@ class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
__out1: None = ...,
__out2: None = ...,
*,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _4Tuple[Optional[str]]] = ...,
+ signature: str | _4Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> _2Tuple[Any]: ...
@overload
@@ -330,16 +328,16 @@ class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]):
self,
__x1: ArrayLike,
__x2: ArrayLike,
- __out1: Optional[NDArray[Any]] = ...,
- __out2: Optional[NDArray[Any]] = ...,
+ __out1: None | NDArray[Any] = ...,
+ __out2: None | NDArray[Any] = ...,
*,
out: _2Tuple[NDArray[Any]] = ...,
- where: Optional[_ArrayLikeBool_co] = ...,
+ where: None | _ArrayLikeBool_co = ...,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _4Tuple[Optional[str]]] = ...,
+ signature: str | _4Tuple[None | str] = ...,
extobj: List[Any] = ...,
) -> _2Tuple[NDArray[Any]]: ...
@@ -384,7 +382,7 @@ class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
axes: List[_2Tuple[SupportsIndex]] = ...,
) -> Any: ...
@@ -393,13 +391,13 @@ class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]):
self,
__x1: ArrayLike,
__x2: ArrayLike,
- out: Union[NDArray[Any], Tuple[NDArray[Any]]],
+ out: NDArray[Any] | Tuple[NDArray[Any]],
*,
casting: _Casting = ...,
order: _OrderKACF = ...,
dtype: DTypeLike = ...,
subok: bool = ...,
- signature: Union[str, _3Tuple[Optional[str]]] = ...,
+ signature: str | _3Tuple[None | str] = ...,
extobj: List[Any] = ...,
axes: List[_2Tuple[SupportsIndex]] = ...,
) -> NDArray[Any]: ...
diff --git a/numpy/typing/mypy_plugin.py b/numpy/typing/mypy_plugin.py
index 901bf4fb1..100e0d957 100644
--- a/numpy/typing/mypy_plugin.py
+++ b/numpy/typing/mypy_plugin.py
@@ -14,7 +14,7 @@ try:
from mypy.build import PRI_MED
_HookFunc = t.Callable[[AnalyzeTypeContext], Type]
- MYPY_EX: t.Optional[ModuleNotFoundError] = None
+ MYPY_EX: None | ModuleNotFoundError = None
except ModuleNotFoundError as ex:
MYPY_EX = ex
@@ -90,7 +90,7 @@ if t.TYPE_CHECKING or MYPY_EX is None:
class _NumpyPlugin(Plugin):
"""A plugin for assigning platform-specific `numpy.number` precisions."""
- def get_type_analyze_hook(self, fullname: str) -> t.Optional[_HookFunc]:
+ def get_type_analyze_hook(self, fullname: str) -> None | _HookFunc:
"""Set the precision of platform-specific `numpy.number` subclasses.
For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.