8000 DOC: add release note for the ``numpy.typing.NBitBase`` deprecation · numpy/numpy@72fcaa9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 72fcaa9

Browse files
committed
DOC: add release note for the numpy.typing.NBitBase deprecation
1 parent d69a9e5 commit 72fcaa9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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: ...

0 commit comments

Comments
 (0)
0