summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-01-15 18:47:33 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2021-01-19 17:05:27 +0100
commit4ef10a55103ddf98730305db11461457cfc93e6e (patch)
tree3977477b092646c75d6c788e3a4641010dc1de6b /numpy
parent00067212c85e4e74a81d4bc3344b51b9364a08e0 (diff)
downloadnumpy-4ef10a55103ddf98730305db11461457cfc93e6e.tar.gz
DOC,TST: Update the `NBitBase` example
Diffstat (limited to 'numpy')
-rw-r--r--numpy/typing/__init__.py6
-rw-r--r--numpy/typing/tests/data/reveal/nbit_base_example.py5
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