python / python/mypy

AssertionError: trying to find dataclass transform spec

Đang mở
#16,062 1 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-dataclasses
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ả

Bug Report
mypy crashes on the example below instead of showing an error or not showing anything.

Encountered today while refactoring a pretty big codebase. Made an accidental mistake, hence the @dataclass(frozen=True)(kw_only=True), but the way Mypy fails won't allow me to find the culprit. I couldn't find a way to debug what was causing an error (--pdb option didn't work for me).

To Reproduce

from dataclasses import dataclass


@dataclass(frozen=True)(kw_only=True)
class Foo:
    bar: str

Gist URL: https://gist.github.com/mypy-play/5b29c7aec29cbab55262d61d8c440ef3
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=5b29c7aec29cbab55262d61d8c440ef3

Expected Behavior
Correctly identified error in the code, or at least no crash

Actual Behavior

mypy mypy_bug.py 
Traceback (most recent call last):
  File "/Users/misha/Dev/python-playground/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/Users/misha/Dev/python-playground/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 94, in main
  File "mypy/main.py", line 173, in run_build
  File "mypy/build.py", line 195, in build
  File "mypy/build.py", line 268, in _build
  File "mypy/build.py", line 2927, in dispatch
  File "mypy/build.py", line 3325, in process_graph
  File "mypy/build.py", line 3420, in process_stale_scc
  File "mypy/semanal_main.py", line 99, in semantic_analysis_for_scc
  File "mypy/semanal_main.py", line 439, in apply_class_plugin_hooks
  File "mypy/semanal_main.py", line 475, in apply_hooks_to_class
  File "mypy/plugins/dataclasses.py", line 930, in dataclass_class_maker_callback
    # contains additional info beyond (and possibly including) the
  File "mypy/plugins/dataclasses.py", line 948, in _get_transform_spec
    _is_kw_only))):
AssertionError: trying to find dataclass transform spec, but reason is neither dataclasses.dataclass nor decorated with typing.dataclass_transform

Your Environment

  • Mypy version used: 1.5.1 (also tried most recent from git, same)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.5

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

Tái hiện lỗi crash bằng ví dụ dataclass và bắt đầu trong mypy/plugins/dataclasses.py, đặc biệt là dataclass_class_maker_callback và _get_transform_spec từ traceback. Kiểm tra cách @dataclass(frozen=True)(kw_only=True) không hợp lệ được xử lý; hoàn tất khi mypy báo lỗi hoặc kết thúc mà không có AssertionError.

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ó
3/5
Thời gian dự kiến
1-2 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
48/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.