pybind11
pybind11 copied to clipboard
feat(types) Numpy.typing.NDArray
trafficstars
Description
Switches to using numpy.typing.NDArray for typing annotations over numpy.ndarray. This is because numpy.ndarray is implemented with the first argument for some future size annotation. See https://github.com/numpy/numpy/issues/16544. Since the first argument is for the size annotation the typing of the numpy.ndarray is basically not being used. I also modified the eigen matrix/tensor to numpy.typing.NDArray as well even though stubgen fails to generate stubs since numpy.typing.NDArray[numpy.float64[...]] is not a valid type.
def foo(x: numpy.typing.NDArray[numpy.float64]) -> None:
reveal_type(x) # ndarray[Any, dtype[floating[_64Bit]]
reveal_type(x.dtype) # dtype[float64]
def bar(x: numpy.ndarray[numpy.float64]) -> None:
reveal_type(x) # ndarray[float64, Any]
reveal_type(x.dtype) # Any
Suggested changelog entry:
Switched to `numpy.typing.NDArray`