8000 ENH: Make `np.number` generic with respect to its precision by BvB93 · Pull Request #17540 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Make np.number generic with respect to its precision #17540

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 12 commits into from
Oct 21, 2020
Merged
Prev Previous commit
Next Next commit
TST: Added a test for the example in the NBitBase docstring
  • Loading branch information
Bas van Beek committed Oct 17, 2020
commit 3082bd7e6b23d6076cc6da8b526862019610202c
18 changes: 18 additions & 0 deletions numpy/typing/tests/data/reveal/nbit_base_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import TypeVar, Union
import numpy as np
import numpy.typing as npt

T = TypeVar("T", bound=npt.NBitBase)

def add(a: np.floating[T], b: np.integer[T]) -> np.floating[T]:
return a + b

i8: np.int64
i4: np.int32
f8: np.float64
f4: np.float32

reveal_type(add(f8, i8)) # E: numpy.floating[numpy.typing._64Bit]
reveal_type(add(f4, i8)) # E: numpy.floating[numpy.typing._64Bit]
reveal_type(add(f8, i4)) # E: numpy.floating[numpy.typing._64Bit]
reveal_type(add(f4, i4)) # E: numpy.floating[numpy.typing._32Bit]
0