python / python/mypy

mypy RecursionError analyzing pint.facets.plain.quantity.PlainQuantity

Đang mở
#21,985 3 bình luận 2 reaction 0 người được giao Xem trên GitHub

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

crash topic-recursive-types
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

mypy crashes with RecursionError while analyzing pint (since pint==0.26.1). Reproduced with compiled and non-compiled mypy.

Traceback

... skipping approx 50000 lines ...
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
RecursionError: maximum recursion depth exceeded
/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/pint/facets/numpy/quantity.py:63: note: use --pdb to drop into pdb
RecursionError: maximum recursion depth exceeded

To Reproduce

I narrowed down the issue to this single import of pint.facets.plain.quantity.PlainQuantity.
Run mypy on a file with this content:

from pint.facets.plain.quantity import PlainQuantity

Your Environment

Issue appears since version 0.26 of pint when they introduced massive type annotations for PlainQuantity. See https://github.com/hgrecco/pint/pull/2302 and https://github.com/hgrecco/pint/pull/2303

  • Mypy version used: 2.3.1 and 1.9.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.12
  • Operating system and version: Fedora 43 in WSL2

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 tái hiện lỗi crash với mypy trong một tệp import pint.facets.plain.quantity.PlainQuantity. Theo dõi quá trình đệ quy qua các đường dẫn đã đề cập là type_visitor.py và types.py, sau đó xác minh rằng việc phân tích cùng import đó hoàn tất mà không có RecursionError.

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
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
52/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.