Dataclass field ordering should not be enforced when init=False
Chưa có ai nhận issue này.
- 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ả
Dataclasses support fields that have default values. All fields with defaults must appear after all fields without default values. Mypy enforces this ordering requirement and emits an error ("Attributes without a default cannot follow attributes with one") if it is violated. Pyright does the same.
By default, dataclasses include a synthesized __init__ method, but this behavior can be overridden by including an init=False argument to the dataclass decorator.
A pyright user recently submitted a bug report indicating that the field order requirement should not be enforced when init=False. I've re-read PEP 557, and it doesn't provide clarity on this point.
Either mypy and pyright are both doing the right thing here or both of them have a bug.
Perhaps someone who was involved in the development of PEP 557, the dataclass implementation, or the mypy dataclass internal plugin could help clarify which behavior is correct?
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 xem xét PEP 557, phần triển khai dataclass và plugin dataclass nội bộ của mypy, sau đó so sánh hành vi được báo cáo trong pyright issue 1753. Xác định xem lỗi thứ tự trường có nên áp dụng khi decorator dataclass sử dụng init=False hay không, và ghi lại hoặc triển khai hành vi đã thống nhất.
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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100