Add a new parameter to `@dataclass` to optionally turn off the synthesizing of a `__replace__` method
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Feature or enhancement
Proposal:
Most (all?) synthesized methods on dataclasses can be turned off:
__init__->init=False__repr__->repr=False__eq__->eq=False__match_args__->match_args=False__slots__->slots=False__lt__(),__le__(),__gt__(),__ge__()->order=False
But __replace__ cannot be turned off, which presents a problem for generic dataclasses: https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092/
I propose this
@dataclass(replace=False)
class D:
x: int
to create a dataclass without __replace__ method.
As far as I can tell, all that's needed is to put a guard around this line:
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
I proposed it in this comment on the DPO thread: https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092/19
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 trong Lib/dataclasses.py, tại dòng được liên kết nơi replace được tổng hợp, và kiểm tra việc xử lý các tham số dataclass xung quanh. Hoàn thành khi một dataclass có replace=False không nhận replace, trong khi hành vi mặc định vẫn không thay đổi; thêm hoặc cập nhật các kiểm thử dataclasses liên quan nếu cần.
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
- backend
- Loại issue
- Tính năng
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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
- 52/100