8000 BUG: Fixed an issue wherein `_GenericAlias.__getitem__` would raise for types with >1 parameters by BvB93 · Pull Request #19094 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fixed an issue wherein _GenericAlias.__getitem__ would raise for types with >1 parameters #19094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MAINT: Change the variance of the npt.ArrayLike to covariant
  • Loading branch information
Bas van Beek committed May 25, 2021
commit 2ed19415920fff8e6fd7b54af747e4aed3a2bff9
4 changes: 2 additions & 2 deletions numpy/typing/_add_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _parse_docstrings() -> str:
add_newdoc('NDArray', repr(NDArray),
"""
A :term:`generic <generic type>` version of
`np.ndarray[Any, np.dtype[~ScalarType]] <numpy.ndarray>`.
`np.ndarray[Any, np.dtype[+ScalarType]] <numpy.ndarray>`.

Can be used during runtime for typing arrays with a given dtype
and unspecified shape.
Expand All @@ -127,7 +127,7 @@ def _parse_docstrings() -> str:
>>> import numpy.typing as npt

>>> print(npt.NDArray)
numpy.ndarray[typing.Any, numpy.dtype[~ScalarType]]
numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]

>>> print(npt.NDArray[np.float64])
numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]
Expand Down
2 changes: 1 addition & 1 deletion numpy/typing/_generic_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __getattribute__(self, name: str) -> Any:
else:
_GENERIC_ALIAS_TYPE = (_GenericAlias,)

ScalarType = TypeVar("ScalarType", bound=np.generic)
ScalarType = TypeVar("ScalarType", bound=np.generic, covariant=True)

if TYPE_CHECKING:
NDArray = np.ndarray[Any, np.dtype[ScalarType]]
Expand Down
2 changes: 1 addition & 1 deletion numpy/typing/tests/test_generic_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
from numpy.typing._generic_alias import _GenericAlias

ScalarType = TypeVar("ScalarType", bound=np.generic)
ScalarType = TypeVar("ScalarType", bound=np.generic, covariant=True)
T1 = TypeVar("T1")
T2 = TypeVar("T2")
DType = _GenericAlias(np.dtype, (ScalarType,))
Expand Down
0