Closed
Description
Describe the issue:
When using numpy.typing, multiplying an array with dtype uint8
by any integer converts the typing dtype to signedinteger
Reproduce the code example:
import numpy as np
from numpy.typing import NDArray
def get_uint8() -> NDArray[np.uint8]:
return np.random.rand(3).astype(np.uint8)
a = get_uint8() # a is correctly NDArray[np.uint8]
b = a * 1 # b is NDArray[signedinteger]
Error message:
`b` in the code shows as `NDArray[signedinteger]`, instead of `NDArray[np.uint8]`
NumPy/Python version information:
$ python -c 'import sys, numpy; print(numpy.__version__, sys.version)'
1.23.4 3.10.7 (main, Nov 14 2022, 18:57:04) [Clang 14.0.0 (clang-1400.0.29.202)]
Context for the issue:
I'm using numpy.typing to differentiate between some arrays of type uint8
and some arrays of type float32
. However, I have to use a cast
every time I multiply an array by a number, which compromises the effectiveness of type checking.