Description
Bug Report
Running mypy on a small file using the pydantic plugin causes mypy to crash. I am reporting this bug because the error message requests it.
The short error message is:
mwe.py:10: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues
version: 1.16.0+dev.1a2dccf1ef10b392f86226f6d72929ac6e03908d
mwe.py:10: : note: please use --show-traceback to print a traceback when reporting a bug
I am aware of #16809, but I don't consider my ticket to be a duplicate. Firstly, that issue was reported almost a year ago and was resolved with a Pydantic update. As I am using the latest version of Pydantic, I believe that I am already using the fix. Secondly, the ticket mentions that the presence of _DeferAnalysis in the traceback indicates an issue with a plugin. In my case, however, this token does not appear in the traceback.
To Reproduce
The python file:
from pydantic import BaseModel, ConfigDict, RootModel
type Models = "SomeModel"
class SomeModel(BaseModel):
name: str
class SomeRootModel(RootModel[list["Models"]]):
pass
The pyproject.toml
file:
[tool.mypy]
plugins = [
"pydantic.mypy"
]
Expected Behavior
Type checking should pass or point out a type related error. In this case, I think it should pass. In any case, a tool should not report that its behaviour indicates a bug.
Actual Behavior
mwe.py:10: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.16.0+dev.1a2dccf1ef10b392f86226f6d72929ac6e03908d
mwe.py:10: : note: use --pdb to drop into pdb
Traceback (most recent call last):
File "/tmp/mypy/.venv/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
main()
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/main.py", line 127, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/main.py", line 211, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/build.py", line 191, in build
result = _build(
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/build.py", line 267, in _build
graph = dispatch(sources, manager, stdout)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/build.py", line 2939, in dispatch
process_graph(graph, manager)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/build.py", line 3337, in process_graph
process_stale_scc(graph, scc, manager)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/build.py", line 3432, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 95, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 222, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 399, in semantic_analyze_target
analyzer.refresh_partial(
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 653, in refresh_partial
self.refresh_top_level(node)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 671, in refresh_top_level
self.accept(d)
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 7331, in accept
node.accept(self)
~~~~~~~~~~~^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/nodes.py", line 1228, in accept
return visitor.visit_class_def(self)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 1771, in visit_class_def
self.analyze_class(defn)
~~~~~~~~~~~~~~~~~~^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 1987, in analyze_class
self.analyze_class_body_common(defn)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 2034, in analyze_class_body_common
self.apply_class_plugin_hooks(defn)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/semanal.py", line 2119, in apply_class_plugin_hooks
hook(ClassDefContext(defn, base_expr, self))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/pydantic/mypy.py", line 162, in _pydantic_model_class_maker_callback
transformer.transform()
~~~~~~~~~~~~~~~~~~~~~^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/pydantic/mypy.py", line 482, in transform
'fields': {field.name: field.serialize() for field in fields},
~~~~~~~~~~~~~~~^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/pydantic/mypy.py", line 378, in serialize
'type': self.type.serialize(),
~~~~~~~~~~~~~~~~~~~^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/types.py", line 1500, in serialize
"args": [arg.serialize() for arg in self.args],
~~~~~~~~~~~~~^^
File "/tmp/mypy/.venv/lib/python3.13/site-packages/mypy/types.py", line 3178, in serialize
assert False, f"Internal error: unresolved placeholder type {self.fullname}"
^^^^^
AssertionError: Internal error: unresolved placeholder type mwe.Models
Your Environment
- Mypy version used: mypy 1.16.0+dev.1a2dccf1ef10b392f86226f6d72929ac6e03908d (compiled: no)
- Mypy command-line flags: --show-traceback
- Mypy configuration options from
mypy.ini
(and other config files):pydantic.mypy
plugin needs to be activated - Python version used: Python 3.13.3 (from Debian Trixie)