Skip to content

Mypy crashes with pydantic plugin enabled: Must not defer during final iteration #15927

Description

@SoptikHa2

Crash Report

When I run mypy on our codebase, it works fine. When I enable pydantic plugin, it crashes.

Pyproject:

[tool.mypy]
plugins = [
"pydantic.mypy"
]
python_version = "3.10"follow_imports = "silent"# Start off with thesewarn_unused_configs = falsewarn_redundant_casts = falsewarn_unused_ignores = false# Getting these passing should be easystrict_equality = falsestrict_concatenate = false# Strongly recommend enabling this one as soon as you cancheck_untyped_defs = false# These shouldn't be too much additional work, but may be tricky to# get passing if you use a lot of untyped librariesdisallow_subclassing_any = falsedisallow_untyped_decorators = falsedisallow_any_generics = false# These next few are various gradations of forcing use of type annotationsdisallow_untyped_calls = falsedisallow_incomplete_defs = falsedisallow_untyped_defs = false# This one isn't too hard to get passing, but return on investment is lowerno_implicit_reexport = false# This one can be tricky to get passing if you use a lot of untyped librarieswarn_return_any = false

Traceback

version: 1.6.0+dev.7141d6bcff9e26e774e88712015ca6bbe8307c9e
Traceback (most recent call last):
File "/Users/foobar/Library/Caches/pypoetry/virtualenvs/foobar-py3.10/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/private/tmp/mypy/mypy/__main__.py", line 15, in console_entry
main()
File "/private/tmp/mypy/mypy/main.py", line 99, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/private/tmp/mypy/mypy/main.py", line 178, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/private/tmp/mypy/mypy/build.py", line 189, in build
result = _build(
File "/private/tmp/mypy/mypy/build.py", line 262, in _build
graph = dispatch(sources, manager, stdout)
File "/private/tmp/mypy/mypy/build.py", line 2938, in dispatch
process_graph(graph, manager)
File "/private/tmp/mypy/mypy/build.py", line 3336, in process_graph
process_stale_scc(graph, scc, manager)
File "/private/tmp/mypy/mypy/build.py", line 3431, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/private/tmp/mypy/mypy/semanal_main.py", line 94, in semantic_analysis_for_scc
process_functions(graph, scc, patches)
File "/private/tmp/mypy/mypy/semanal_main.py", line 252, in process_functions
process_top_level_function(
File "/private/tmp/mypy/mypy/semanal_main.py", line 291, in process_top_level_function
deferred, incomplete, progress = semantic_analyze_target(
File "/private/tmp/mypy/mypy/semanal_main.py", line 349, in semantic_analyze_target
analyzer.refresh_partial(
File "/private/tmp/mypy/mypy/semanal.py", line 603, in refresh_partial
self.accept(node)
File "/private/tmp/mypy/mypy/semanal.py", line 6477, in accept
node.accept(self)
File "/private/tmp/mypy/mypy/nodes.py", line 790, in accept
return visitor.visit_func_def(self)
File "/private/tmp/mypy/mypy/semanal.py", line 833, in visit_func_def
self.analyze_func_def(defn)
File "/private/tmp/mypy/mypy/semanal.py", line 868, in analyze_func_def
self.defer(defn)
File "/private/tmp/mypy/mypy/semanal.py", line 6149, in defer
assert not self.final_iteration, "Must not defer during final iteration"
AssertionError: Must not defer during final iteration

To Reproduce

fromtypingimport*frompydanticimportBaseModelAnyBaseFoo=TypeVar("AnyBaseFoo", bound="BaseFoo")
classBaseFoo:
passclassFoo(BaseModel, Generic[AnyBaseFoo]):
pass

Your Environment

  • Mypy version used: 1.6.0+dev.7141d6bcff9e26e774e88712015ca6bbe8307c9e
  • Mypy command-line flags: mypy foobar/baz --show-traceback
  • Python version used: 3.10.10
  • Operating system and version: Darwin mac 22.6.0, rosetta was used

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions