You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rng.integers(low, high) returns an np.int64, but the type hint incorrectly says it returns an int.
This causes problems later, in code such as this:
importtorchimportnumpyasnpx=rng.integers(0, 10)
torch.set_grad_enabled(x==4)
# TypeError: set_grad_enabled(): argument 'enabled' (position 1) must be bool, not numpy.bool_
Reproduce the code example:
importnumpyasnprng=np.random.default_rng()
x=rng.integers(0, 10)
assertisinstance(x.item(), int) # fails at type-checkingassertisinstance(x, int) # fails at runtime
Error message:
# mypy error
test.py:6: error: "int" has no attribute "item" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
# runtime error
Traceback (most recent call last):
File "/app/test.py", line 7, in<module>
assert isinstance(x, int)
~~~~~~~~~~^^^^^^^^
AssertionError
Describe the issue:
rng.integers(low, high)
returns annp.int64
, but the type hint incorrectly says it returns anint
.This causes problems later, in code such as this:
Reproduce the code example:
Error message:
Python and NumPy Versions:
numpy: 2.2.4
Python: 3.13.2 (main, Feb 6 2025, 23:44:09) [GCC 12.2.0]
Type-checker version and settings:
Mypy version:
Mypy was run with
mypy .
in an otherwise empty directory (inpython:3
Docker image).Additional typing packages.
Packages were installed with
pip install mypy numpy
, resulting in the following installations:The text was updated successfully, but these errors were encountered: