8000 MAINT: Changed the `NBitBase` variancy in `number` from co- to invariant by BvB93 · Pull Request #18174 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Changed the NBitBase variancy in number from co- to invariant #18174

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 5 commits into from
Jan 19, 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
Next Next commit
DOC,TST: Update the NBitBase example
  • Loading branch information
Bas van Beek committed Jan 19, 2021
commit 4ef10a55103ddf98730305db11461457cfc93e6e
6 changes: 4 additions & 2 deletions numpy/typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions numpy/typing/tests/data/reveal/nbit_base_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
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
Expand Down
0