[New-bugs-announce] [issue32513] dataclasses: make it easier to use user-supplied special methods

Eric V. Smith report at bugs.python.org
Sun Jan 7 12:06:05 EST 2018

New submission from Eric V. Smith <eric at trueblade.com>:

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:
and if using frozen=True, also:

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.

assignee: eric.smith
messages: 309628
nosy: eric.smith
priority: normal
severity: normal
status: open
title: dataclasses: make it easier to use user-supplied special methods
type: behavior
versions: Python 3.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list