mypy icon indicating copy to clipboard operation
mypy copied to clipboard

When importing numpy>=2.0.0, report "AssertionError: Internal error: unresolved placeholder type None" when using stubgen

Open JunChen1990 opened this issue 1 year ago • 2 comments

Bug Report

When importing lastest version of numpy>=2.0.0, report "AssertionError: Internal error: unresolved placeholder type None" when using stubgen.

The error looks like this:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Program Files\Python\Python312\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 3468, 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

To Reproduce

Install latest version of numpy>=2.0.0, then create a Python file with only this import, egg. foo.py.

import numpy

using the stubgen command to generate pyi file

# stubgen .\foo.py

Expected Behavior

gernerated the pyi file via stubgen command

Actual Behavior

report "AssertionError: Internal error: unresolved placeholder type None" when using stubgen command.

I tried to downgrade numpy to numpy==1.26.4 and it worked.

Your Environment

  • Mypy version used: 1.10.1
  • Mypy command-line flags: stubgen .\foo.py
  • Mypy configuration options from mypy.ini (and other config files): default
  • Python version used: 3.12.3

JunChen1990 avatar Jul 19 '24 03:07 JunChen1990

I have the same issue here. For now, the solution is to use version 1.26.4 of the Numpy...

fcdiass avatar Jul 29 '24 16:07 fcdiass

This is being tackled in #17396

varunagrawal avatar Aug 26 '24 09:08 varunagrawal

Fixed by #18585

brianschubert avatar Jun 09 '25 16:06 brianschubert