Skip to content

Crash: Must not defer during final iteration #20486

Description

@cbornet

Crash Report

Mypy crashed when changing the import path of the parent class.

./langchain_core/language_models/base.py:116: 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.19.1

Traceback

Traceback (most recent call last):
  File "mypy/semanal.py", line 7568, in accept
  File "mypy/nodes.py", line 995, in accept
  File "mypy/semanal.py", line 978, in visit_func_def
  File "mypy/semanal.py", line 1023, in analyze_func_def
  File "mypy/semanal.py", line 7214, in defer
AssertionError: Must not defer during final iteration

The crash happens on checking

class BaseLanguageModel(
    RunnableSerializable[LanguageModelInput, LanguageModelOutputVar], ABC
)

when changing the RunnableSerializable import from

from langchain_core.runnables import Runnable, RunnableSerializable

to

from langchain_core.runnables.base import Runnable, RunnableSerializable

To Reproduce

See langchain-ai/langchain#34520

  • clone the project
git clone https://github.com/cbornet/langchain.git
  • checkout PR branch
git checkout fix-tc
  • go to core sub-project
cd core
  • run mypy (using uv)
uv run --all-groups mypy . --show-traceback

Your Environment

  • Mypy version used: 1.18.2, 1.19.1
  • Mypy command-line flags:
  • Mypy configuration options from pyproject.toml:
plugins = ["pydantic.mypy"]
strict = true
enable_error_code = "deprecated"
disallow_any_generics = false
  • Python version used: 3.10, 3.11, 3.12, 3.13, 3.14
  • Operating system and version: macOS 15.1, Ubuntu 24.04

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions