Open tomsilver opened 3 weeks ago
I also got the same error running stubgen
on a package, when an (non-direct) ancestor dependency used numpy>=2.0
.
Thanks for the issue.
I minimised the repro, in case someone has time to look into it:
rm -rf repro
mkdir repro
mkdir repro/np
echo 'from .arraysetops import UniqueAllResult' > repro/np/__init__.pyi
echo '
from typing import Generic, NamedTuple, TypeVar
from np import does_not_exist
from np.missing import also_missing
_SCT = TypeVar("_SCT", bound=does_not_exist)
class UniqueAllResult(NamedTuple, Generic[_SCT]):
values: also_missing[_SCT]
' > repro/np/arraysetops.pyi
touch repro/np/py.typed
PYTHONPATH=repro mypy -c 'import np'
(also standard disclaimer: a global --follow-imports
flag is fairly niche and in practice I've seen more misuse of it than legitimate use)
Thank you for looking into this @hauntsaninja. Would you mind clarifying what does_not_exist
and also_missing
are in the numpy stub file? It looks from your reproducer that there's something to fix there for us in numpy, and it has to do with numpy.generic
, numpy.number
, typing.Generic
and/or numpy._typing.NDArray`. But they all seem to exist as far as I can tell.
@rgommers I don't think there's anything for numpy to do here, this just needs to be fixed in mypy. --follow-imports error
is an unusual setting that makes mypy not resolve imports.
That said, there is one unrelated case of a missing import in numpy's type stubs that would be good to fix:
numpy/ma/extras.pyi:2: error: Cannot find implementation or library stub for module named "numpy.lib.index_tricks" [import-not-found]
Thanks @hauntsaninja. I opened a PR to fix that issue, it should land in numpy 2.0.1.
Running stubgen over from numpy import array
also fails with this error.
Running attached test.txt Windows batch script results in;
Python 3.11.9
mypy==1.10.0
mypy-extensions==1.0.0
numpy==2.0.0
typing_extensions==4.12.2
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Temp\mypy\.venv\Scripts\stubgen.exe\__main__.py", line 7, in <module>
File "mypy\stubgen.py", line 1882, in main
File "mypy\stubgen.py", line 1678, in generate_stubs
File "mypy\stubgen.py", line 1610, in generate_asts_for_modules
File "mypy\build.py", line 192, in build
File "mypy\build.py", line 266, in _build
File "mypy\build.py", line 2942, in dispatch
File "mypy\build.py", line 3340, in process_graph
File "mypy\build.py", line 3467, in process_stale_scc
File "mypy\build.py", line 2503, in write_cache
File "mypy\build.py", line 1564, in write_cache
File "mypy\nodes.py", line 387, in serialize
File "mypy\nodes.py", line 3936, in serialize
File "mypy\nodes.py", line 3873, in serialize
File "mypy\nodes.py", line 3304, in serialize
File "mypy\types.py", line 667, in serialize
File "mypy\types.py", line 2430, in serialize
File "mypy\types.py", line 1468, in serialize
File "mypy\types.py", line 667, in serialize
File "mypy\types.py", line 3067, in serialize
AssertionError: Internal error: unresolved placeholder type None
If this helps at all, stubgen from mypy < 1.5.0 does not produce this error when generating stubs for modules that use numpy 2.0.0.
This is a mypy crash revealed by the release of numpy 2.0.0. See also https://github.com/numpy/numpy/issues/26720
Crash Report
The crash is shown below. Notes:
Traceback
To Reproduce
pip install numpy mypy
echo "import numpy" > test.py
mypy test.py --follow-imports error
Your Environment
--follow-imports error
mypy.ini
(and other config files): N/A