diff options
-rw-r--r-- | numpy/typing/__init__.py | 6 | ||||
-rw-r--r-- | numpy/typing/tests/data/reveal/nbit_base_example.py | 5 |
2 files changed, 7 insertions, 4 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py index 3cfdfe50a..3c15c7c0b 100644 --- a/numpy/typing/__init__.py +++ b/numpy/typing/__init__.py @@ -184,13 +184,15 @@ class NBitBase: .. code-block:: python + >>> from __future__ import annotations >>> from typing import TypeVar, TYPE_CHECKING >>> import numpy as np >>> import numpy.typing as npt - >>> T = TypeVar("T", bound=npt.NBitBase) + >>> T1 = TypeVar("T1", bound=npt.NBitBase) + >>> T2 = TypeVar("T2", bound=npt.NBitBase) - >>> def add(a: "np.floating[T]", b: "np.integer[T]") -> "np.floating[T]": + >>> def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[Union[T1, T2]]: ... return a + b >>> a = np.float16() diff --git a/numpy/typing/tests/data/reveal/nbit_base_example.py b/numpy/typing/tests/data/reveal/nbit_base_example.py index 99fb71560..d34f6f69a 100644 --- a/numpy/typing/tests/data/reveal/nbit_base_example.py +++ b/numpy/typing/tests/data/reveal/nbit_base_example.py @@ -2,9 +2,10 @@ from typing import TypeVar, Union import numpy as np import numpy.typing as npt -T = TypeVar("T", bound=npt.NBitBase) +T1 = TypeVar("T1", bound=npt.NBitBase) +T2 = TypeVar("T2", bound=npt.NBitBase) -def add(a: np.floating[T], b: np.integer[T]) -> np.floating[T]: +def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[Union[T1, T2]]: return a + b i8: np.int64 |