-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues related to numpy #18343
Comments
PR adding mypy_primer to numpy's CI: numpy/numpy#28073 |
PR fixing a crash when using numpy with weird import following settings: #18351 |
PR improving diagnostics for some case someone ran into using numpy: #16875 |
Not sure if this has been reported before, but the following line is causing stubtest to crash with Line 673 in 60da03a
Because since NumPy 2.2.0, >>> import numpy as np
>>> np.__version__
'2.2.0'
>>> a = np.array([])
>>> a
array([], dtype=float64)
>>> a == object() # numpy "vectorizes" the `==` over each element
array([], dtype=bool)
>>> bool(a == object())
Traceback (most recent call last):
File "<python-input-24>", line 1, in <module>
bool(a == object())
~~~~^^^^^^^^^^^^^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty. So when stubtest encounters a $ stubtest --mypy-config-file=pyproject.toml --allowlist=.mypyignore --ignore-unused-allowlist scipy
Traceback (most recent call last):
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/bin/stubtest", line [8](https://github.com/jorenham/scipy-stubs/actions/runs/12246812991/job/34163454128?pr=288#step:7:9), in <module>
sys.exit(main())
~~~~^^
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 20[9](https://github.com/jorenham/scipy-stubs/actions/runs/12246812991/job/34163454128?pr=288#step:7:10)8, in main
return test_stubs(parse_options(sys.argv[1:]))
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 1971, in test_stubs
for error in test_module(module):
~~~~~~~~~~~^^^^^^^^
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 247, in test_module
yield from verify(stub, runtime, [module_name])
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 423, in verify_mypyfile
yield from verify(stub_entry, runtime_entry, object_path + [entry])
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 578, in verify_typeinfo
yield from verify(stub_to_verify, runtime_attr, object_path + [entry])
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line [10](https://github.com/jorenham/scipy-stubs/actions/runs/12246812991/job/34163454128?pr=288#step:7:11)64, in verify_funcitem
for message in _verify_signature(stub_sig, runtime_sig, function_name=stub.name):
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.[13](https://github.com/jorenham/scipy-stubs/actions/runs/12246812991/job/34163454128?pr=288#step:7:14)/site-packages/mypy/stubtest.py", line 902, in _verify_signature
yield from _verify_arg_default_value(stub_arg, runtime_arg)
File "/home/runner/work/scipy-stubs/scipy-stubs/.venv/lib/python3.13/site-packages/mypy/stubtest.py", line 664, in _verify_arg_default_value
if runtime_arg.default != inspect.Parameter.empty:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.
Error: Process completed with exit code 1. Luckily, fixing this is just a matter of replacing I could scrape together a PR if you'd like, but that could take some time (of which I don't have a lot the coming week) as I don't have a local dev env for mypy setup at the moment. And I can imagine that's more mypy-savvy could probably fix this in a coffee break on their nokia 3310 (assuming they don't get distracted and end up playing snake 2, of course). Anyway, I wouldn't mind either way, so let me know 🤷🏻. |
Thanks for the report, fix is here #18353 |
This can be a tracking issue.
See also numpy/numpy#27957
The text was updated successfully, but these errors were encountered: