diff options
author | Bas van Beek <b.f.van.beek@vu.nl> | 2022-01-24 17:17:35 +0100 |
---|---|---|
committer | Bas van Beek <b.f.van.beek@vu.nl> | 2022-01-24 17:29:03 +0100 |
commit | 5264dc220dc208e533bdbdcafa9f4f06ddb04aab (patch) | |
tree | 5c3035d8acba53fe3a4efe9600f7a88eceefa055 /numpy/typing | |
parent | 6218e76bc590e9253ed8d4c4b18c74aa81332b15 (diff) | |
download | numpy-5264dc220dc208e533bdbdcafa9f4f06ddb04aab.tar.gz |
MAINT: Create the `_DTypeLike` type-alias in `numpy.typing`
Represents a subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic`
Diffstat (limited to 'numpy/typing')
-rw-r--r-- | numpy/typing/__init__.py | 1 | ||||
-rw-r--r-- | numpy/typing/_dtype_like.py | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py index 72ac750ae..acef90ce4 100644 --- a/numpy/typing/__init__.py +++ b/numpy/typing/__init__.py @@ -323,6 +323,7 @@ from ._scalars import ( from ._shape import _Shape, _ShapeLike from ._dtype_like import ( DTypeLike as DTypeLike, + _DTypeLike, _SupportsDType, _VoidDTypeLike, _DTypeLikeBool, diff --git a/numpy/typing/_dtype_like.py b/numpy/typing/_dtype_like.py index c9bf1a137..b705d82fd 100644 --- a/numpy/typing/_dtype_like.py +++ b/numpy/typing/_dtype_like.py @@ -57,9 +57,12 @@ from ._char_codes import ( _ObjectCodes, ) -_DTypeLikeNested = Any # TODO: wait for support for recursive types +_SCT = TypeVar("_SCT", bound=np.generic) _DType_co = TypeVar("_DType_co", covariant=True, bound=DType[Any]) +_DTypeLikeNested = Any # TODO: wait for support for recursive types + + # Mandatory keys class _DTypeDictBase(TypedDict): names: Sequence[str] @@ -82,6 +85,14 @@ class _SupportsDType(Protocol[_DType_co]): def dtype(self) -> _DType_co: ... +# A subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic` +_DTypeLike = Union[ + "np.dtype[_SCT]", + Type[_SCT], + _SupportsDType["np.dtype[_SCT]"], +] + + # Would create a dtype[np.void] _VoidDTypeLike = Union[ # (flexible_dtype, itemsize) |