[Python-Dev] Concerns about method overriding and subclassing with dataclasses (original) (raw)
Guido van Rossum guido at python.org
Tue Jan 2 00:01:15 EST 2018
- Previous message (by thread): [Python-Dev] Concerns about method overriding and subclassing with dataclasses
- Next message (by thread): [Python-Dev] Concerns about method overriding and subclassing with dataclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jan 1, 2018 at 8:50 PM, Ethan Smith <ethan at ethanhs.me> wrote:
On Mon, Jan 1, 2018 at 5:03 PM, Chris Barker <chris.barker at noaa.gov> wrote: 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 interpreted Guido's proposal as being about all methods -- we may want something special for repr, but I hope not. [...] I interpreted this to be for all methods as well, which makes sense. Special casing just repr doesn't make sense to me, but I will wait for Guido to clarify.
Indeed, I just wrote repr for simplicity. This should apply to all special methods. (Though there may be some complications for eq/ne and for the ordering operators.)
On Mon, Jan 1, 2018 at 9:44 PM, Chris Barker <chris.barker at noaa.gov> wrote:
On Mon, Jan 1, 2018 at 7:50 PM, Ethan Smith <ethan at ethanhs.me> wrote:
Will you get the "right" repr now if you derive a dataclass from a dataclass? That would be a nice feature.
The repr will be generated by the child dataclass unless the user overrides it. So I believe this is the "right" repr. what I was wondering is if the child will know about all the fields in the parent -- so it could make a full repr.
Yes, there's a class variable (dataclass_fields) that identifies the parent fields. The PEP doesn't mention this or the fact that special methods (like repr and init) can tell whether a base class is a dataclass. It probably should though. (@Eric)
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180101/c445078f/attachment.html>
- Previous message (by thread): [Python-Dev] Concerns about method overriding and subclassing with dataclasses
- Next message (by thread): [Python-Dev] Concerns about method overriding and subclassing with dataclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]