Add a new parameter to `@dataclass` to optionally turn off the synthesizing of a `__replace__` method
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/dataclasses.py 中合成 replace 的連結行開始,檢查周圍的 dataclass 參數處理。完成標準是:replace=False 的 dataclass 不會取得 replace,同時預設行為維持不變;視需要新增或更新相關的 dataclasses 測試。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 功能
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 52/100