Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
Open
Labels
Description
Describe the issue:
Followup of#27957 because the issue is not fixed fornumpy.linalg.inv.
numpy.linalg.inv apparently loses some typing information.
The following snippet is a test case demonstrating the issue. In my real code, I tried to pass inv_test to a function that only acceptsNDArray[np.float64]. I'd expect an inversion to keep the same float size in type.
Reproduce the code example:
importnumpyasnpimportnumpy.typingasnpttest:npt.NDArray[np.float64]=np.array([1.0,2.0,3.0],dtype=np.float64)inv_test:npt.NDArray[np.float64]=np.linalg.inv(test)
Error message:
test.py:5: error: Incompatible typesin assignment (expression hastype"ndarray[tuple[Any, ...], dtype[floating[Any]]]", variable hastype"ndarray[tuple[Any, ...], dtype[float64]]") [assignment]Found 1 errorin 1 file (checked 1source file)
Python and NumPy Versions:
numpy: 2.3.5
python: 3.14.0 (main, Oct 7 2025, 09:34:52) [GCC 14.3.0]
Type-checker version and settings:
❯ mypy --versionmypy 1.19.0 (compiled: yes)I usedmypy test.py andmypy --local-partial-types --allow-redefinition-new test.py, same result.
Additional typing packages.
typing_extensions: 4.15.0