This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients eric.smith
Date 2018-01-07.17:06:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1515344765.63.0.467229070634.issue32513@psf.upfronthosting.co.za>
In-reply-to
Content
Modify dataclasses to make it easier to specify special methods.

For example: currently, if you want to override __repr__, you need to specify @dataclass(repr=False), and also provide your own __repr__. Also, it's current an error to not specify repr=False and to also provide your own __repr__.  @dataclass should be able to determine that if you provide __repr__, you don't want it to provide it's own __repr__.

The methods that @dataclass will provide for you are:
__init__
__repr__
__eq__
__ne__
__lt__
__le__
__gt__
__ge__
_hash__
and if using frozen=True, also:
__setattr__
__delattr__

Per the discussion that started at https://mail.python.org/pipermail/python-dev/2017-December/151487.html, the change will be to override these methods only if:
1. the method would have been generated based on @dataclass params, and
2. the method is not present in the class's __dict__.

The first item is to allow the user to continue to suppress method generation, and the second item is so that base-class methods are not considered in the decision.

I'm still thinking through how __eq__ and __ne__ should be handled (as well as the ordering comparisons, too). I'll raise an issue on python-dev and point it here.
History
Date User Action Args
2018-01-07 17:06:05eric.smithsetrecipients: + eric.smith
2018-01-07 17:06:05eric.smithsetmessageid: <1515344765.63.0.467229070634.issue32513@psf.upfronthosting.co.za>
2018-01-07 17:06:05eric.smithlinkissue32513 messages
2018-01-07 17:06:05eric.smithcreate