diff options
author | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-08-14 21:39:50 +0200 |
---|---|---|
committer | Bas van Beek <b.f.van.beek@vu.nl> | 2021-08-30 15:26:54 +0200 |
commit | d0b676b77bfa567eddb925bc31ead24ff0b576b1 (patch) | |
tree | 07b44648afab1077871a8bb330e9e183f7865c25 | |
parent | 5ae53e93b2be9ccf47bf72a85d71ea15d15a2eed (diff) | |
download | numpy-d0b676b77bfa567eddb925bc31ead24ff0b576b1.tar.gz |
MAINT: Drop .py code-paths specific to Python 3.7
-rw-r--r-- | numpy/typing/__init__.py | 19 | ||||
-rw-r--r-- | numpy/typing/_array_like.py | 26 | ||||
-rw-r--r-- | numpy/typing/_callable.py | 587 | ||||
-rw-r--r-- | numpy/typing/_char_codes.py | 282 | ||||
-rw-r--r-- | numpy/typing/_dtype_like.py | 51 | ||||
-rw-r--r-- | numpy/typing/_shape.py | 12 | ||||
-rw-r--r-- | numpy/typing/tests/test_runtime.py | 10 |
7 files changed, 417 insertions, 570 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py index d731f00ef..bfa7982c0 100644 --- a/numpy/typing/__init__.py +++ b/numpy/typing/__init__.py @@ -143,24 +143,7 @@ API # NOTE: The API section will be appended with additional entries # further down in this file -from typing import TYPE_CHECKING, List, Any - -if TYPE_CHECKING: - # typing_extensions is always available when type-checking - from typing_extensions import Literal as L - _HAS_TYPING_EXTENSIONS: L[True] -else: - try: - import typing_extensions - except ImportError: - _HAS_TYPING_EXTENSIONS = False - else: - _HAS_TYPING_EXTENSIONS = True - -if TYPE_CHECKING: - from typing_extensions import final -else: - def final(f): return f +from typing import TYPE_CHECKING, List, Any, final if not TYPE_CHECKING: __all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray"] diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py index c562f3c1f..6ea0eb662 100644 --- a/numpy/typing/_array_like.py +++ b/numpy/typing/_array_like.py @@ -1,7 +1,6 @@ from __future__ import annotations -import sys -from typing import Any, Sequence, TYPE_CHECKING, Union, TypeVar, Generic +from typing import Any, Sequence, Protocol, Union, TypeVar from numpy import ( ndarray, dtype, @@ -19,28 +18,19 @@ from numpy import ( str_, bytes_, ) -from . import _HAS_TYPING_EXTENSIONS - -if sys.version_info >= (3, 8): - from typing import Protocol -elif _HAS_TYPING_EXTENSIONS: - from typing_extensions import Protocol _T = TypeVar("_T") _ScalarType = TypeVar("_ScalarType", bound=generic) _DType = TypeVar("_DType", bound="dtype[Any]") _DType_co = TypeVar("_DType_co", covariant=True, bound="dtype[Any]") -if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS or sys.version_info >= (3, 8): - # The `_SupportsArray` protocol only cares about the default dtype - # (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned - # array. - # Concrete implementations of the protocol are responsible for adding - # any and all remaining overloads - class _SupportsArray(Protocol[_DType_co]): - def __array__(self) -> ndarray[Any, _DType_co]: ... -else: - class _SupportsArray(Generic[_DType_co]): ... +# The `_SupportsArray` protocol only cares about the default dtype +# (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned +# array. +# Concrete implementations of the protocol are responsible for adding +# any and all remaining overloads +class _SupportsArray(Protocol[_DType_co]): + def __array__(self) -> ndarray[Any, _DType_co]: ... # TODO: Wait for support for recursive types _NestedSequence = Union[ diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py index 8f911da3b..63a8153af 100644 --- a/numpy/typing/_callable.py +++ b/numpy/typing/_callable.py @@ -10,7 +10,6 @@ See the `Mypy documentation`_ on protocols for more details. from __future__ import annotations -import sys from typing import ( Union, TypeVar, @@ -18,7 +17,7 @@ from typing import ( Any, Tuple, NoReturn, - TYPE_CHECKING, + Protocol, ) from numpy import ( @@ -45,312 +44,282 @@ from ._scalars import ( _FloatLike_co, _NumberLike_co, ) -from . import NBitBase, _HAS_TYPING_EXTENSIONS +from . import NBitBase from ._generic_alias import NDArray -if sys.version_info >= (3, 8): - from typing import Protocol -elif _HAS_TYPING_EXTENSIONS: - from typing_extensions import Protocol - -if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS or sys.version_info >= (3, 8): - _T1 = TypeVar("_T1") - _T2 = TypeVar("_T2") - _2Tuple = Tuple[_T1, _T1] - - _NBit1 = TypeVar("_NBit1", bound=NBitBase) - _NBit2 = TypeVar("_NBit2", bound=NBitBase) - - _IntType = TypeVar("_IntType", bound=integer) - _FloatType = TypeVar("_FloatType", bound=floating) - _NumberType = TypeVar("_NumberType", bound=number) - _NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number) - _GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic) - - class _BoolOp(Protocol[_GenericType_co]): - @overload - def __call__(self, __other: _BoolLike_co) -> _GenericType_co: ... - @overload # platform dependent - def __call__(self, __other: int) -> int_: ... - @overload - def __call__(self, __other: float) -> float64: ... - @overload - def __call__(self, __other: complex) -> complex128: ... - @overload - def __call__(self, __other: _NumberType) -> _NumberType: ... - - class _BoolBitOp(Protocol[_GenericType_co]): - @overload - def __call__(self, __other: _BoolLike_co) -> _GenericType_co: ... - @overload # platform dependent - def __call__(self, __other: int) -> int_: ... - @overload - def __call__(self, __other: _IntType) -> _IntType: ... - - class _BoolSub(Protocol): - # Note that `__other: bool_` is absent here - @overload - def __call__(self, __other: bool) -> NoReturn: ... - @overload # platform dependent - def __call__(self, __other: int) -> int_: ... - @overload - def __call__(self, __other: float) -> float64: ... - @overload - def __call__(self, __other: complex) -> complex128: ... - @overload - def __call__(self, __other: _NumberType) -> _NumberType: ... - - class _BoolTrueDiv(Protocol): - @overload - def __call__(self, __other: float | _IntLike_co) -> float64: ... - @overload - def __call__(self, __other: complex) -> complex128: ... - @overload - def __call__(self, __other: _NumberType) -> _NumberType: ... - - class _BoolMod(Protocol): - @overload - def __call__(self, __other: _BoolLike_co) -> int8: ... - @overload # platform dependent - def __call__(self, __other: int) -> int_: ... - @overload - def __call__(self, __other: float) -> float64: ... - @overload - def __call__(self, __other: _IntType) -> _IntType: ... - @overload - def __call__(self, __other: _FloatType) -> _FloatType: ... - - class _BoolDivMod(Protocol): - @overload - def __call__(self, __other: _BoolLike_co) -> _2Tuple[int8]: ... - @overload # platform dependent - def __call__(self, __other: int) -> _2Tuple[int_]: ... - @overload - def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... - @overload - def __call__(self, __other: _IntType) -> _2Tuple[_IntType]: ... - @overload - def __call__(self, __other: _FloatType) -> _2Tuple[_FloatType]: ... - - class _TD64Div(Protocol[_NumberType_co]): - @overload - def __call__(self, __other: timedelta64) -> _NumberType_co: ... - @overload - def __call__(self, __other: _BoolLike_co) -> NoReturn: ... - @overload - def __call__(self, __other: _FloatLike_co) -> timedelta64: ... - - class _IntTrueDiv(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> floating[_NBit1]: ... - @overload - def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: complex - ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... - @overload - def __call__(self, __other: integer[_NBit2]) -> floating[_NBit1 | _NBit2]: ... - - class _UnsignedIntOp(Protocol[_NBit1]): - # NOTE: `uint64 + signedinteger -> float64` - @overload - def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... - @overload - def __call__( - self, __other: int | signedinteger[Any] - ) -> Any: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: complex - ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: unsignedinteger[_NBit2] - ) -> unsignedinteger[_NBit1 | _NBit2]: ... - - class _UnsignedIntBitOp(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... - @overload - def __call__(self, __other: int) -> signedinteger[Any]: ... - @overload - def __call__(self, __other: signedinteger[Any]) -> signedinteger[Any]: ... - @overload - def __call__( - self, __other: unsignedinteger[_NBit2] - ) -> unsignedinteger[_NBit1 | _NBit2]: ... - - class _UnsignedIntMod(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... - @overload - def __call__( - self, __other: int | signedinteger[Any] - ) -> Any: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: unsignedinteger[_NBit2] - ) -> unsignedinteger[_NBit1 | _NBit2]: ... - - class _UnsignedIntDivMod(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ... - @overload - def __call__( - self, __other: int | signedinteger[Any] - ) -> _2Tuple[Any]: ... - @overload - def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... - @overload - def __call__( - self, __other: unsignedinteger[_NBit2] - ) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ... - - class _SignedIntOp(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... - @overload - def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: complex - ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: signedinteger[_NBit2] - ) -> signedinteger[_NBit1 | _NBit2]: ... - - class _SignedIntBitOp(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... - @overload - def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... - @overload - def __call__( - self, __other: signedinteger[_NBit2] - ) -> signedinteger[_NBit1 | _NBit2]: ... - - class _SignedIntMod(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... - @overload - def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: signedinteger[_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[_NBit1 | _NBitInt]]: ... - @overload - def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... - @overload - def __call__( - self, __other: signedinteger[_NBit2] - ) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ... - - class _FloatOp(Protocol[_NBit1]): - @overload - def __call__(self, __other: bool) -> floating[_NBit1]: ... - @overload - def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, __other: complex - ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... - @overload - def __call__( - 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[_NBit1 | _NBitInt]: ... - @overload - def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... - @overload - def __call__( - 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[_NBit1 | _NBitInt]]: ... - @overload - def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... - @overload - def __call__( - 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[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ... - @overload - def __call__( - self, __other: complex - ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... - @overload - def __call__( - self, - __other: Union[ - integer[_NBit2], - floating[_NBit2], - complexfloating[_NBit2, _NBit2], - ] - ) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ... - - class _NumberOp(Protocol): - def __call__(self, __other: _NumberLike_co) -> Any: ... - - class _ComparisonOp(Protocol[_T1, _T2]): - @overload - def __call__(self, __other: _T1) -> bool_: ... - @overload - def __call__(self, __other: _T2) -> NDArray[bool_]: ... - -else: - _BoolOp = Any - _BoolBitOp = Any - _BoolSub = Any - _BoolTrueDiv = Any - _BoolMod = Any - _BoolDivMod = Any - _TD64Div = Any - _IntTrueDiv = Any - _UnsignedIntOp = Any - _UnsignedIntBitOp = Any - _UnsignedIntMod = Any - _UnsignedIntDivMod = Any - _SignedIntOp = Any - _SignedIntBitOp = Any - _SignedIntMod = Any - _SignedIntDivMod = Any - _FloatOp = Any - _FloatMod = Any - _FloatDivMod = Any - _ComplexOp = Any - _NumberOp = Any - _ComparisonOp = Any +_T1 = TypeVar("_T1") +_T2 = TypeVar("_T2") +_2Tuple = Tuple[_T1, _T1] + +_NBit1 = TypeVar("_NBit1", bound=NBitBase) +_NBit2 = TypeVar("_NBit2", bound=NBitBase) + +_IntType = TypeVar("_IntType", bound=integer) +_FloatType = TypeVar("_FloatType", bound=floating) +_NumberType = TypeVar("_NumberType", bound=number) +_NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number) +_GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic) + +class _BoolOp(Protocol[_GenericType_co]): + @overload + def __call__(self, __other: _BoolLike_co) -> _GenericType_co: ... + @overload # platform dependent + def __call__(self, __other: int) -> int_: ... + @overload + def __call__(self, __other: float) -> float64: ... + @overload + def __call__(self, __other: complex) -> complex128: ... + @overload + def __call__(self, __other: _NumberType) -> _NumberType: ... + +class _BoolBitOp(Protocol[_GenericType_co]): + @overload + def __call__(self, __other: _BoolLike_co) -> _GenericType_co: ... + @overload # platform dependent + def __call__(self, __other: int) -> int_: ... + @overload + def __call__(self, __other: _IntType) -> _IntType: ... + +class _BoolSub(Protocol): + # Note that `__other: bool_` is absent here + @overload + def __call__(self, __other: bool) -> NoReturn: ... + @overload # platform dependent + def __call__(self, __other: int) -> int_: ... + @overload + def __call__(self, __other: float) -> float64: ... + @overload + def __call__(self, __other: complex) -> complex128: ... + @overload + def __call__(self, __other: _NumberType) -> _NumberType: ... + +class _BoolTrueDiv(Protocol): + @overload + def __call__(self, __other: float | _IntLike_co) -> float64: ... + @overload + def __call__(self, __other: complex) -> complex128: ... + @overload + def __call__(self, __other: _NumberType) -> _NumberType: ... + +class _BoolMod(Protocol): + @overload + def __call__(self, __other: _BoolLike_co) -> int8: ... + @overload # platform dependent + def __call__(self, __other: int) -> int_: ... + @overload + def __call__(self, __other: float) -> float64: ... + @overload + def __call__(self, __other: _IntType) -> _IntType: ... + @overload + def __call__(self, __other: _FloatType) -> _FloatType: ... + +class _BoolDivMod(Protocol): + @overload + def __call__(self, __other: _BoolLike_co) -> _2Tuple[int8]: ... + @overload # platform dependent + def __call__(self, __other: int) -> _2Tuple[int_]: ... + @overload + def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... + @overload + def __call__(self, __other: _IntType) -> _2Tuple[_IntType]: ... + @overload + def __call__(self, __other: _FloatType) -> _2Tuple[_FloatType]: ... + +class _TD64Div(Protocol[_NumberType_co]): + @overload + def __call__(self, __other: timedelta64) -> _NumberType_co: ... + @overload + def __call__(self, __other: _BoolLike_co) -> NoReturn: ... + @overload + def __call__(self, __other: _FloatLike_co) -> timedelta64: ... + +class _IntTrueDiv(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> floating[_NBit1]: ... + @overload + def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: complex + ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... + @overload + def __call__(self, __other: integer[_NBit2]) -> floating[_NBit1 | _NBit2]: ... + +class _UnsignedIntOp(Protocol[_NBit1]): + # NOTE: `uint64 + signedinteger -> float64` + @overload + def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... + @overload + def __call__( + self, __other: int | signedinteger[Any] + ) -> Any: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: complex + ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: unsignedinteger[_NBit2] + ) -> unsignedinteger[_NBit1 | _NBit2]: ... + +class _UnsignedIntBitOp(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... + @overload + def __call__(self, __other: int) -> signedinteger[Any]: ... + @overload + def __call__(self, __other: signedinteger[Any]) -> signedinteger[Any]: ... + @overload + def __call__( + self, __other: unsignedinteger[_NBit2] + ) -> unsignedinteger[_NBit1 | _NBit2]: ... + +class _UnsignedIntMod(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ... + @overload + def __call__( + self, __other: int | signedinteger[Any] + ) -> Any: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: unsignedinteger[_NBit2] + ) -> unsignedinteger[_NBit1 | _NBit2]: ... + +class _UnsignedIntDivMod(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ... + @overload + def __call__( + self, __other: int | signedinteger[Any] + ) -> _2Tuple[Any]: ... + @overload + def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... + @overload + def __call__( + self, __other: unsignedinteger[_NBit2] + ) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ... + +class _SignedIntOp(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: complex + ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: signedinteger[_NBit2] + ) -> signedinteger[_NBit1 | _NBit2]: ... + +class _SignedIntBitOp(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... + @overload + def __call__( + self, __other: signedinteger[_NBit2] + ) -> signedinteger[_NBit1 | _NBit2]: ... + +class _SignedIntMod(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: signedinteger[_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[_NBit1 | _NBitInt]]: ... + @overload + def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... + @overload + def __call__( + self, __other: signedinteger[_NBit2] + ) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ... + +class _FloatOp(Protocol[_NBit1]): + @overload + def __call__(self, __other: bool) -> floating[_NBit1]: ... + @overload + def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, __other: complex + ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... + @overload + def __call__( + 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[_NBit1 | _NBitInt]: ... + @overload + def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ... + @overload + def __call__( + 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[_NBit1 | _NBitInt]]: ... + @overload + def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ... + @overload + def __call__( + 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[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ... + @overload + def __call__( + self, __other: complex + ) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ... + @overload + def __call__( + self, + __other: Union[ + integer[_NBit2], + floating[_NBit2], + complexfloating[_NBit2, _NBit2], + ] + ) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ... + +class _NumberOp(Protocol): + def __call__(self, __other: _NumberLike_co) -> Any: ... + +class _ComparisonOp(Protocol[_T1, _T2]): + @overload + def __call__(self, __other: _T1) -> bool_: ... + @overload + def __call__(self, __other: _T2) -> NDArray[bool_]: ... diff --git a/numpy/typing/_char_codes.py b/numpy/typing/_char_codes.py index 22ee168e9..139471084 100644 --- a/numpy/typing/_char_codes.py +++ b/numpy/typing/_char_codes.py @@ -1,171 +1,111 @@ -import sys -from typing import Any, TYPE_CHECKING - -from . import _HAS_TYPING_EXTENSIONS - -if sys.version_info >= (3, 8): - from typing import Literal -elif _HAS_TYPING_EXTENSIONS: - from typing_extensions import Literal - -if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS or sys.version_info >= (3, 8): - _BoolCodes = Literal["?", "=?", "<?", ">?", "bool", "bool_", "bool8"] - - _UInt8Codes = Literal["uint8", "u1", "=u1", "<u1", ">u1"] - _UInt16Codes = Literal["uint16", "u2", "=u2", "<u2", ">u2"] - _UInt32Codes = Literal["uint32", "u4", "=u4", "<u4", ">u4"] - _UInt64Codes = Literal["uint64", "u8", "=u8", "<u8", ">u8"] - - _Int8Codes = Literal["int8", "i1", "=i1", "<i1", ">i1"] - _Int16Codes = Literal["int16", "i2", "=i2", "<i2", ">i2"] - _Int32Codes = Literal["int32", "i4", "=i4", "<i4", ">i4"] - _Int64Codes = Literal["int64", "i8", "=i8", "<i8", ">i8"] - - _Float16Codes = Literal["float16", "f2", "=f2", "<f2", ">f2"] - _Float32Codes = Literal["float32", "f4", "=f4", "<f4", ">f4"] - _Float64Codes = Literal["float64", "f8", "=f8", "<f8", ">f8"] - - _Complex64Codes = Literal["complex64", "c8", "=c8", "<c8", ">c8"] - _Complex128Codes = Literal["complex128", "c16", "=c16", "<c16", ">c16"] - - _ByteCodes = Literal["byte", "b", "=b", "<b", ">b"] - _ShortCodes = Literal["short", "h", "=h", "<h", ">h"] - _IntCCodes = Literal["intc", "i", "=i", "<i", ">i"] - _IntPCodes = Literal["intp", "int0", "p", "=p", "<p", ">p"] - _IntCodes = Literal["long", "int", "int_", "l", "=l", "<l", ">l"] - _LongLongCodes = Literal["longlong", "q", "=q", "<q", ">q"] - - _UByteCodes = Literal["ubyte", "B", "=B", "<B", ">B"] - _UShortCodes = Literal["ushort", "H", "=H", "<H", ">H"] - _UIntCCodes = Literal["uintc", "I", "=I", "<I", ">I"] - _UIntPCodes = Literal["uintp", "uint0", "P", "=P", "<P", ">P"] - _UIntCodes = Literal["uint", "L", "=L", "<L", ">L"] - _ULongLongCodes = Literal["ulonglong", "Q", "=Q", "<Q", ">Q"] - - _HalfCodes = Literal["half", "e", "=e", "<e", ">e"] - _SingleCodes = Literal["single", "f", "=f", "<f", ">f"] - _DoubleCodes = Literal["double", "float", "float_", "d", "=d", "<d", ">d"] - _LongDoubleCodes = Literal["longdouble", "longfloat", "g", "=g", "<g", ">g"] - - _CSingleCodes = Literal["csingle", "singlecomplex", "F", "=F", "<F", ">F"] - _CDoubleCodes = Literal["cdouble", "complex", "complex_", "cfloat", "D", "=D", "<D", ">D"] - _CLongDoubleCodes = Literal["clongdouble", "clongfloat", "longcomplex", "G", "=G", "<G", ">G"] - - _StrCodes = Literal["str", "str_", "str0", "unicode", "unicode_", "U", "=U", "<U", ">U"] - _BytesCodes = Literal["bytes", "bytes_", "bytes0", "S", "=S", "<S", ">S"] - _VoidCodes = Literal["void", "void0", "V", "=V", "<V", ">V"] - _ObjectCodes = Literal["object", "object_", "O", "=O", "<O", ">O"] - - _DT64Codes = Literal[ - "datetime64", "=datetime64", "<datetime64", ">datetime64", - "datetime64[Y]", "=datetime64[Y]", "<datetime64[Y]", ">datetime64[Y]", - "datetime64[M]", "=datetime64[M]", "<datetime64[M]", ">datetime64[M]", - "datetime64[W]", "=datetime64[W]", "<datetime64[W]", ">datetime64[W]", - "datetime64[D]", "=datetime64[D]", "<datetime64[D]", ">datetime64[D]", - "datetime64[h]", "=datetime64[h]", "<datetime64[h]", ">datetime64[h]", - "datetime64[m]", "=datetime64[m]", "<datetime64[m]", ">datetime64[m]", - "datetime64[s]", "=datetime64[s]", "<datetime64[s]", ">datetime64[s]", - "datetime64[ms]", "=datetime64[ms]", "<datetime64[ms]", ">datetime64[ms]", - "datetime64[us]", "=datetime64[us]", "<datetime64[us]", ">datetime64[us]", - "datetime64[ns]", "=datetime64[ns]", "<datetime64[ns]", ">datetime64[ns]", - "datetime64[ps]", "=datetime64[ps]", "<datetime64[ps]", ">datetime64[ps]", - "datetime64[fs]", "=datetime64[fs]", "<datetime64[fs]", ">datetime64[fs]", - "datetime64[as]", "=datetime64[as]", "<datetime64[as]", ">datetime64[as]", - "M", "=M", "<M", ">M", - "M8", "=M8", "<M8", ">M8", - "M8[Y]", "=M8[Y]", "<M8[Y]", ">M8[Y]", - "M8[M]", "=M8[M]", "<M8[M]", ">M8[M]", - "M8[W]", "=M8[W]", "<M8[W]", ">M8[W]", - "M8[D]", "=M8[D]", "<M8[D]", ">M8[D]", - "M8[h]", "=M8[h]", "<M8[h]", ">M8[h]", - "M8[m]", "=M8[m]", "<M8[m]", ">M8[m]", - "M8[s]", "=M8[s]", "<M8[s]", ">M8[s]", - "M8[ms]", "=M8[ms]", "<M8[ms]", ">M8[ms]", - "M8[us]", "=M8[us]", "<M8[us]", ">M8[us]", - "M8[ns]", "=M8[ns]", "<M8[ns]", ">M8[ns]", - "M8[ps]", "=M8[ps]", "<M8[ps]", ">M8[ps]", - "M8[fs]", "=M8[fs]", "<M8[fs]", ">M8[fs]", - "M8[as]", "=M8[as]", "<M8[as]", ">M8[as]", - ] - _TD64Codes = Literal[ - "timedelta64", "=timedelta64", "<timedelta64", ">timedelta64", - "timedelta64[Y]", "=timedelta64[Y]", "<timedelta64[Y]", ">timedelta64[Y]", - "timedelta64[M]", "=timedelta64[M]", "<timedelta64[M]", ">timedelta64[M]", - "timedelta64[W]", "=timedelta64[W]", "<timedelta64[W]", ">timedelta64[W]", - "timedelta64[D]", "=timedelta64[D]", "<timedelta64[D]", ">timedelta64[D]", - "timedelta64[h]", "=timedelta64[h]", "<timedelta64[h]", ">timedelta64[h]", - "timedelta64[m]", "=timedelta64[m]", "<timedelta64[m]", ">timedelta64[m]", - "timedelta64[s]", "=timedelta64[s]", "<timedelta64[s]", ">timedelta64[s]", - "timedelta64[ms]", "=timedelta64[ms]", "<timedelta64[ms]", ">timedelta64[ms]", - "timedelta64[us]", "=timedelta64[us]", "<timedelta64[us]", ">timedelta64[us]", - "timedelta64[ns]", "=timedelta64[ns]", "<timedelta64[ns]", ">timedelta64[ns]", - "timedelta64[ps]", "=timedelta64[ps]", "<timedelta64[ps]", ">timedelta64[ps]", - "timedelta64[fs]", "=timedelta64[fs]", "<timedelta64[fs]", ">timedelta64[fs]", - "timedelta64[as]", "=timedelta64[as]", "<timedelta64[as]", ">timedelta64[as]", - "m", "=m", "<m", ">m", - "m8", "=m8", "<m8", ">m8", - "m8[Y]", "=m8[Y]", "<m8[Y]", ">m8[Y]", - "m8[M]", "=m8[M]", "<m8[M]", ">m8[M]", - "m8[W]", "=m8[W]", "<m8[W]", ">m8[W]", - "m8[D]", "=m8[D]", "<m8[D]", ">m8[D]", - "m8[h]", "=m8[h]", "<m8[h]", ">m8[h]", - "m8[m]", "=m8[m]", "<m8[m]", ">m8[m]", - "m8[s]", "=m8[s]", "<m8[s]", ">m8[s]", - "m8[ms]", "=m8[ms]", "<m8[ms]", ">m8[ms]", - "m8[us]", "=m8[us]", "<m8[us]", ">m8[us]", - "m8[ns]", "=m8[ns]", "<m8[ns]", ">m8[ns]", - "m8[ps]", "=m8[ps]", "<m8[ps]", ">m8[ps]", - "m8[fs]", "=m8[fs]", "<m8[fs]", ">m8[fs]", - "m8[as]", "=m8[as]", "<m8[as]", ">m8[as]", - ] - -else: - _BoolCodes = Any - - _UInt8Codes = Any - _UInt16Codes = Any - _UInt32Codes = Any - _UInt64Codes = Any - - _Int8Codes = Any - _Int16Codes = Any - _Int32Codes = Any - _Int64Codes = Any - - _Float16Codes = Any - _Float32Codes = Any - _Float64Codes = Any - - _Complex64Codes = Any - _Complex128Codes = Any - - _ByteCodes = Any - _ShortCodes = Any - _IntCCodes = Any - _IntPCodes = Any - _IntCodes = Any - _LongLongCodes = Any - - _UByteCodes = Any - _UShortCodes = Any - _UIntCCodes = Any - _UIntPCodes = Any - _UIntCodes = Any - _ULongLongCodes = Any - - _HalfCodes = Any - _SingleCodes = Any - _DoubleCodes = Any - _LongDoubleCodes = Any - - _CSingleCodes = Any - _CDoubleCodes = Any - _CLongDoubleCodes = Any - - _StrCodes = Any - _BytesCodes = Any - _VoidCodes = Any - _ObjectCodes = Any - - _DT64Codes = Any - _TD64Codes = Any +from typing import Literal + +_BoolCodes = Literal["?", "=?", "<?", ">?", "bool", "bool_", "bool8"] + +_UInt8Codes = Literal["uint8", "u1", "=u1", "<u1", ">u1"] +_UInt16Codes = Literal["uint16", "u2", "=u2", "<u2", ">u2"] +_UInt32Codes = Literal["uint32", "u4", "=u4", "<u4", ">u4"] +_UInt64Codes = Literal["uint64", "u8", "=u8", "<u8", ">u8"] + +_Int8Codes = Literal["int8", "i1", "=i1", "<i1", ">i1"] +_Int16Codes = Literal["int16", "i2", "=i2", "<i2", ">i2"] +_Int32Codes = Literal["int32", "i4", "=i4", "<i4", ">i4"] +_Int64Codes = Literal["int64", "i8", "=i8", "<i8", ">i8"] + +_Float16Codes = Literal["float16", "f2", "=f2", "<f2", ">f2"] +_Float32Codes = Literal["float32", "f4", "=f4", "<f4", ">f4"] +_Float64Codes = Literal["float64", "f8", "=f8", "<f8", ">f8"] + +_Complex64Codes = Literal["complex64", "c8", "=c8", "<c8", ">c8"] +_Complex128Codes = Literal["complex128", "c16", "=c16", "<c16", ">c16"] + +_ByteCodes = Literal["byte", "b", "=b", "<b", ">b"] +_ShortCodes = Literal["short", "h", "=h", "<h", ">h"] +_IntCCodes = Literal["intc", "i", "=i", "<i", ">i"] +_IntPCodes = Literal["intp", "int0", "p", "=p", "<p", ">p"] +_IntCodes = Literal["long", "int", "int_", "l", "=l", "<l", ">l"] +_LongLongCodes = Literal["longlong", "q", "=q", "<q", ">q"] + +_UByteCodes = Literal["ubyte", "B", "=B", "<B", ">B"] +_UShortCodes = Literal["ushort", "H", "=H", "<H", ">H"] +_UIntCCodes = Literal["uintc", "I", "=I", "<I", ">I"] +_UIntPCodes = Literal["uintp", "uint0", "P", "=P", "<P", ">P"] +_UIntCodes = Literal["uint", "L", "=L", "<L", ">L"] +_ULongLongCodes = Literal["ulonglong", "Q", "=Q", "<Q", ">Q"] + +_HalfCodes = Literal["half", "e", "=e", "<e", ">e"] +_SingleCodes = Literal["single", "f", "=f", "<f", ">f"] +_DoubleCodes = Literal["double", "float", "float_", "d", "=d", "<d", ">d"] +_LongDoubleCodes = Literal["longdouble", "longfloat", "g", "=g", "<g", ">g"] + +_CSingleCodes = Literal["csingle", "singlecomplex", "F", "=F", "<F", ">F"] +_CDoubleCodes = Literal["cdouble", "complex", "complex_", "cfloat", "D", "=D", "<D", ">D"] +_CLongDoubleCodes = Literal["clongdouble", "clongfloat", "longcomplex", "G", "=G", "<G", ">G"] + +_StrCodes = Literal["str", "str_", "str0", "unicode", "unicode_", "U", "=U", "<U", ">U"] +_BytesCodes = Literal["bytes", "bytes_", "bytes0", "S", "=S", "<S", ">S"] +_VoidCodes = Literal["void", "void0", "V", "=V", "<V", ">V"] +_ObjectCodes = Literal["object", "object_", "O", "=O", "<O", ">O"] + +_DT64Codes = Literal[ + "datetime64", "=datetime64", "<datetime64", ">datetime64", + "datetime64[Y]", "=datetime64[Y]", "<datetime64[Y]", ">datetime64[Y]", + "datetime64[M]", "=datetime64[M]", "<datetime64[M]", ">datetime64[M]", + "datetime64[W]", "=datetime64[W]", "<datetime64[W]", ">datetime64[W]", + "datetime64[D]", "=datetime64[D]", "<datetime64[D]", ">datetime64[D]", + "datetime64[h]", "=datetime64[h]", "<datetime64[h]", ">datetime64[h]", + "datetime64[m]", "=datetime64[m]", "<datetime64[m]", ">datetime64[m]", + "datetime64[s]", "=datetime64[s]", "<datetime64[s]", ">datetime64[s]", + "datetime64[ms]", "=datetime64[ms]", "<datetime64[ms]", ">datetime64[ms]", + "datetime64[us]", "=datetime64[us]", "<datetime64[us]", ">datetime64[us]", + "datetime64[ns]", "=datetime64[ns]", "<datetime64[ns]", ">datetime64[ns]", + "datetime64[ps]", "=datetime64[ps]", "<datetime64[ps]", ">datetime64[ps]", + "datetime64[fs]", "=datetime64[fs]", "<datetime64[fs]", ">datetime64[fs]", + "datetime64[as]", "=datetime64[as]", "<datetime64[as]", ">datetime64[as]", + "M", "=M", "<M", ">M", + "M8", "=M8", "<M8", ">M8", + "M8[Y]", "=M8[Y]", "<M8[Y]", ">M8[Y]", + "M8[M]", "=M8[M]", "<M8[M]", ">M8[M]", + "M8[W]", "=M8[W]", "<M8[W]", ">M8[W]", + "M8[D]", "=M8[D]", "<M8[D]", ">M8[D]", + "M8[h]", "=M8[h]", "<M8[h]", ">M8[h]", + "M8[m]", "=M8[m]", "<M8[m]", ">M8[m]", + "M8[s]", "=M8[s]", "<M8[s]", ">M8[s]", + "M8[ms]", "=M8[ms]", "<M8[ms]", ">M8[ms]", + "M8[us]", "=M8[us]", "<M8[us]", ">M8[us]", + "M8[ns]", "=M8[ns]", "<M8[ns]", ">M8[ns]", + "M8[ps]", "=M8[ps]", "<M8[ps]", ">M8[ps]", + "M8[fs]", "=M8[fs]", "<M8[fs]", ">M8[fs]", + "M8[as]", "=M8[as]", "<M8[as]", ">M8[as]", +] +_TD64Codes = Literal[ + "timedelta64", "=timedelta64", "<timedelta64", ">timedelta64", + "timedelta64[Y]", "=timedelta64[Y]", "<timedelta64[Y]", ">timedelta64[Y]", + "timedelta64[M]", "=timedelta64[M]", "<timedelta64[M]", ">timedelta64[M]", + "timedelta64[W]", "=timedelta64[W]", "<timedelta64[W]", ">timedelta64[W]", + "timedelta64[D]", "=timedelta64[D]", "<timedelta64[D]", ">timedelta64[D]", + "timedelta64[h]", "=timedelta64[h]", "<timedelta64[h]", ">timedelta64[h]", + "timedelta64[m]", "=timedelta64[m]", "<timedelta64[m]", ">timedelta64[m]", + "timedelta64[s]", "=timedelta64[s]", "<timedelta64[s]", ">timedelta64[s]", + "timedelta64[ms]", "=timedelta64[ms]", "<timedelta64[ms]", ">timedelta64[ms]", + "timedelta64[us]", "=timedelta64[us]", "<timedelta64[us]", ">timedelta64[us]", + "timedelta64[ns]", "=timedelta64[ns]", "<timedelta64[ns]", ">timedelta64[ns]", + "timedelta64[ps]", "=timedelta64[ps]", "<timedelta64[ps]", ">timedelta64[ps]", + "timedelta64[fs]", "=timedelta64[fs]", "<timedelta64[fs]", ">timedelta64[fs]", + "timedelta64[as]", "=timedelta64[as]", "<timedelta64[as]", ">timedelta64[as]", + "m", "=m", "<m", ">m", + "m8", "=m8", "<m8", ">m8", + "m8[Y]", "=m8[Y]", "<m8[Y]", ">m8[Y]", + "m8[M]", "=m8[M]", "<m8[M]", ">m8[M]", + "m8[W]", "=m8[W]", "<m8[W]", ">m8[W]", + "m8[D]", "=m8[D]", "<m8[D]", ">m8[D]", + "m8[h]", "=m8[h]", "<m8[h]", ">m8[h]", + "m8[m]", "=m8[m]", "<m8[m]", ">m8[m]", + "m8[s]", "=m8[s]", "<m8[s]", ">m8[s]", + "m8[ms]", "=m8[ms]", "<m8[ms]", ">m8[ms]", + "m8[us]", "=m8[us]", "<m8[us]", ">m8[us]", + "m8[ns]", "=m8[ns]", "<m8[ns]", ">m8[ns]", + "m8[ps]", "=m8[ps]", "<m8[ps]", ">m8[ps]", + "m8[fs]", "=m8[fs]", "<m8[fs]", ">m8[fs]", + "m8[as]", "=m8[as]", "<m8[as]", ">m8[as]", +] diff --git a/numpy/typing/_dtype_like.py b/numpy/typing/_dtype_like.py index b2ce3adb4..0955f5b18 100644 --- a/numpy/typing/_dtype_like.py +++ b/numpy/typing/_dtype_like.py @@ -1,19 +1,10 @@ -import sys -from typing import Any, List, Sequence, Tuple, Union, Type, TypeVar, TYPE_CHECKING +from typing import Any, List, Sequence, Tuple, Union, Type, TypeVar, Protocol, TypedDict import numpy as np -from . import _HAS_TYPING_EXTENSIONS from ._shape import _ShapeLike from ._generic_alias import _DType as DType -if sys.version_info >= (3, 8): - from typing import Protocol, TypedDict -elif _HAS_TYPING_EXTENSIONS: - from typing_extensions import Protocol, TypedDict -else: - from ._generic_alias import _GenericAlias as GenericAlias - from ._char_codes import ( _BoolCodes, _UInt8Codes, @@ -59,30 +50,22 @@ from ._char_codes import ( _DTypeLikeNested = Any # TODO: wait for support for recursive types _DType_co = TypeVar("_DType_co", covariant=True, bound=DType[Any]) -if TYPE_CHECKING or _HAS_TYPING_EXTENSIONS or sys.version_info >= (3, 8): - # Mandatory keys - class _DTypeDictBase(TypedDict): - names: Sequence[str] - formats: Sequence[_DTypeLikeNested] - - # Mandatory + optional keys - class _DTypeDict(_DTypeDictBase, total=False): - offsets: Sequence[int] - titles: Sequence[Any] # Only `str` elements are usable as indexing aliases, but all objects are legal - itemsize: int - aligned: bool - - # A protocol for anything with the dtype attribute - class _SupportsDType(Protocol[_DType_co]): - @property - def dtype(self) -> _DType_co: ... - -else: - _DTypeDict = Any - - class _SupportsDType: ... - _SupportsDType = GenericAlias(_SupportsDType, _DType_co) - +# Mandatory keys +class _DTypeDictBase(TypedDict): + names: Sequence[str] + formats: Sequence[_DTypeLikeNested] + +# Mandatory + optional keys +class _DTypeDict(_DTypeDictBase, total=False): + offsets: Sequence[int] + titles: Sequence[Any] # Only `str` elements are usable as indexing aliases, but all objects are legal + itemsize: int + aligned: bool + +# A protocol for anything with the dtype attribute +class _SupportsDType(Protocol[_DType_co]): + @property + def dtype(self) -> _DType_co: ... # Would create a dtype[np.void] _VoidDTypeLike = Union[ diff --git a/numpy/typing/_shape.py b/numpy/typing/_shape.py index 75698f3d3..c28859b19 100644 --- a/numpy/typing/_shape.py +++ b/numpy/typing/_shape.py @@ -1,14 +1,4 @@ -import sys -from typing import Sequence, Tuple, Union, Any - -from . import _HAS_TYPING_EXTENSIONS - -if sys.version_info >= (3, 8): - from typing import SupportsIndex -elif _HAS_TYPING_EXTENSIONS: - from typing_extensions import SupportsIndex -else: - SupportsIndex = Any +from typing import Sequence, Tuple, Union, SupportsIndex _Shape = Tuple[int, ...] diff --git a/numpy/typing/tests/test_runtime.py b/numpy/typing/tests/test_runtime.py index e82b08ac2..151b06bed 100644 --- a/numpy/typing/tests/test_runtime.py +++ b/numpy/typing/tests/test_runtime.py @@ -3,18 +3,12 @@ from __future__ import annotations import sys -from typing import get_type_hints, Union, Tuple, NamedTuple +from typing import get_type_hints, Union, Tuple, NamedTuple, get_args, get_origin import pytest import numpy as np import numpy.typing as npt -try: - from typing_extensions import get_args, get_origin - SKIP = False -except ImportError: - SKIP = True - class TypeTup(NamedTuple): typ: type @@ -36,7 +30,6 @@ TYPES = { @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) -@pytest.mark.skipif(SKIP, reason="requires typing-extensions") def test_get_args(name: type, tup: TypeTup) -> None: """Test `typing.get_args`.""" typ, ref = tup.typ, tup.args @@ -45,7 +38,6 @@ def test_get_args(name: type, tup: TypeTup) -> None: @pytest.mark.parametrize("name,tup", TYPES.items(), ids=TYPES.keys()) -@pytest.mark.skipif(SKIP, reason="requires typing-extensions") def test_get_origin(name: type, tup: TypeTup) -> None: """Test `typing.get_origin`.""" typ, ref = tup.typ, tup.origin |