Skip to content

Daemon crashes with a decorator returning Generic/Protocol, decorated method returning Self, and an undefined symbol #20132

@bzoracler

Description

@bzoracler

Crash Report & To Reproduce

With a relatively simple reproducer and small example, this causes a crash. Anything larger than a small example will cause dmypy to hang.

  1. Set up the following dummy project
  2. cd project
  3. dmypy run
  4. Change project/src/pkg/utils.py (e.g. add a = 1234 at the end of this file)
  5. dmypy run again (crashes)

Dummy project:

project/
    src/
        pkg/
            __init__.py (blank)
            module.py
            utils.py
    mypy.ini
  • mypy.ini

    [mypy]
    files = src/
    
  • module.py

    from typing_extensions import Self
    from pkg.utils import deco
    
    var = UNDEFINED_SYMBOL
    
    class A:
        @deco
        def mymethod(self) -> Self: ...
  • utils.py

    from collections.abc import Callable
    from typing import Protocol, TypeVar
    from typing_extensions import ParamSpec
    
    _P = ParamSpec("_P")
    _R_co = TypeVar("_R_co", covariant=True)
    _T = TypeVar("_T")
    
    def deco(f: Callable[_P, _T], /) -> _Method[_P, _T]: ...
    
    class _Method(Protocol[_P, _R_co]): ...

Traceback

Runtime error from non-compiled mypy is below on master (commit 842a8fd)

Daemon crashed!
Traceback (most recent call last):
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 237, in serve
    resp = self.run_command(command, data)
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 286, in run_command
    ret = method(self, **data)
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 354, in cmd_run
    return self.check(sources, export_types, is_tty, terminal_width)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 433, in check
    messages = self.fine_grained_increment_follow_imports(
        sources, explicit_export_types=export_types
    )
  File ".../python3.13/site-packages/mypy/dmypy_server.py", line 640, in fine_grained_increment_follow_imports
    messages = fine_grained_manager.update(changed, [], followed=True)
  File ".../python3.13/site-packages/mypy/server/update.py", line 286, in update
    changed_modules = propagate_changes_using_dependencies(
        self.manager,
    ...<5 lines>...
        self.processed_targets,
    )
  File ".../lib/python3.13/site-packages/mypy/server/update.py", line 857, in propagate_changes_using_dependencies
    raise RuntimeError("Max number of iterations (%d) reached (endless loop?)" % MAX_ITER)
RuntimeError: Max number of iterations (1000) reached (endless loop?)

Your Environment

  • Mypy version used: 1.18.2, master
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.13
  • Operating system and version: Pop OS! 22.04 LTS

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions