-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
Multiplying an NDArray[np.uint8] by 1 converts the mypy type into NDArray[signedinteger]
Consider the following code:
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]
In the last line, b shows as NDArray[signedinteger] instead of NDArray[np.uint8]. There is no obvious reason why multplying an np.uint8 by 1 should change the dtype. Indeed if we add a print:
print('b.dtype', b.dtype)
... this outputs b.dtype uint8
Expected Behavior
- in the program above, the mypy type for
bshould beNDArray[np.uint8]
Actual Behavior
- in the program above, the mypy type for
bisNDArray[signedinteger]
Your Environment
$ python -V
Python 3.10.7
$ pip freeze | grep mypy
mypy==0.991
mypy-extensions==0.4.3
$ pip freeze | grep numpy
numpy==1.23.4
$ uname -a
Darwin Hughs-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:11:33 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T8110 arm64
$ cat setup.cfg
[mypy]
ignore_missing_imports = True
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong