| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + ``numpy.typing.NBitBase`` deprecation | ||
| 2 | + ------------------------------------- | ||
| 3 | + The ``numpy.typing.NBitBase`` type has been deprecated and will be removed in a future version. | ||
| 4 | + | ||
| 5 | + This type was previously intended to be used as a generic upper bound for type-parameters, for example: | ||
| 6 | + | ||
| 7 | + .. code-block:: python | ||
| 8 | + | ||
| 9 | + import numpy as np | ||
| 10 | + import numpy.typing as npt | ||
| 11 | + | ||
| 12 | + def f[NT: npt.NBitBase](x: np.complexfloating[NT]) -> np.floating[NT]: ... | ||
| 13 | + | ||
| 14 | + But in NumPy 2.2.0, ``float64`` and ``complex128`` were changed to concrete subtypes, causing static type-checkers to reject ``x: np.float64 = f(np.complex128(42j))``. | ||
| 15 | + | ||
| 16 | + So instead, the better approach is to use ``typing.overload``: | ||
| 17 | + | ||
| 18 | + .. code-block:: python | ||
| 19 | + | ||
| 20 | + import numpy as np | ||
| 21 | + from typing import overload | ||
| 22 | + | ||
| 23 | + @overload | ||
| 24 | + def f(x: np.complex64) -> np.float32: ... | ||
| 25 | + @overload | ||
| 26 | + def f(x: np.complex128) -> np.float64: ... | ||
| 27 | + @overload | ||
| 28 | + def f(x: np.clongdouble) -> np.longdouble: ... | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments