From 5a5f800cbe82b581653dd3db3d489916b3479e13 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Mon, 22 Nov 2021 14:15:31 +0100 Subject: [PATCH] BUG: Fix an incorrect protocol used in `np.lib.shape_base` --- numpy/lib/shape_base.pyi | 4 ++-- numpy/typing/tests/data/fail/shape_base.pyi | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 numpy/typing/tests/data/fail/shape_base.pyi diff --git a/numpy/lib/shape_base.pyi b/numpy/lib/shape_base.pyi index 8aa283d0291f..17016c99928b 100644 --- a/numpy/lib/shape_base.pyi +++ b/numpy/lib/shape_base.pyi @@ -18,7 +18,7 @@ from numpy.typing import ( NDArray, _ShapeLike, _FiniteNestedSequence, - _SupportsDType, + _SupportsArray, _ArrayLikeBool_co, _ArrayLikeUInt_co, _ArrayLikeInt_co, @@ -31,7 +31,7 @@ from numpy.core.shape_base import vstack _SCT = TypeVar("_SCT", bound=generic) -_ArrayLike = _FiniteNestedSequence[_SupportsDType[dtype[_SCT]]] +_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] # The signatures of `__array_wrap__` and `__array_prepare__` are the same; # give them unique names for the sake of clarity diff --git a/numpy/typing/tests/data/fail/shape_base.pyi b/numpy/typing/tests/data/fail/shape_base.pyi new file mode 100644 index 000000000000..e709741b7935 --- /dev/null +++ b/numpy/typing/tests/data/fail/shape_base.pyi @@ -0,0 +1,8 @@ +import numpy as np + +class DTypeLike: + dtype: np.dtype[np.int_] + +dtype_like: DTypeLike + +np.expand_dims(dtype_like, (5, 10)) # E: No overload variant