-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
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: intto create a dataclass without __replace__ method.
As far as I can tell, all that's needed is to put a guard around this line:
Line 1098 in a4709e5
| _set_new_attribute(cls, '__replace__', _replace) |
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
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement