python / python/mypy

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

Đang mở
#20,132 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

crash topic-daemon topic-fine-grained-incremental
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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 https://github.com/python/mypy/commit/842a8fdcaa711c92c1067d373098844eb7d1ab57)

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy project dummy được cung cấp với dmypy, sau đó kiểm tra các đường dẫn traceback trong mypy/dmypy_server.py và mypy/server/update.py, đặc biệt là việc truyền dependency tăng dần. Tái hiện lần chạy dmypy thứ hai sau khi thay đổi utils.py; được xem là hoàn tất khi daemon không bị crash hoặc treo và việc kiểm tra hoàn tất bình thường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.