[Python-Dev] Concerns about method overriding and subclassing with dataclasses (original) (raw)

Chris Barker chris.barker at noaa.gov
Mon Jan 1 20:03:38 EST 2018


On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull < turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:

Just use the simple rule that a new repr is generated unless provided in the dataclass.

are we only talking about repr here ???

I interpretted Guido's proposal as being about all methods -- we may want something special for repr, but I hope not.

But +1 for Guido's proposal, not only because it's easy to explain, but because it more naturally follows the usual inheritance logic:

The decorator's entire point is to auto-generate boilerplate code for you. Once it's done that it shouldn't, in the end, behave any differently than if you hand wrote that code. If you hand wrote the methods that the decorator creates for you, they would override any base class versions. So that's what it should do.

And the fact that you can optionally tell it not to in some particular case keeps full flexibility.

-CHB

I grant that there may be many reasons why one would be deriving

dataclasses from dataclasses

Will you get the "right" repr now if you derive a datacalss from a dataclass? That would be a nice feature.

-CHB

--

Christopher Barker, Ph.D. Oceanographer

Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180101/5d985e8c/attachment.html>



More information about the Python-Dev mailing list