[Python-Dev] Concerns about method overriding and subclassing with dataclasses (original) (raw)
Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Sat Dec 30 10:27:22 EST 2017
- 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 ]
Ethan Furman writes:
Good point. So auto-generate a new repr if:
- one is not provided, and
- existing repr is either:
- object.repr, or
- a previous dataclass repr
-0.5 I'm with Guido here. Just use the simple rule that a new repr is generated unless provided in the dataclass.
The logic I use (Guido seems to be just arguing for "simple" for now) is that a dataclass is "usually" going to add fields, which you "normally" want exposed in the repr, and that means that an inherited repr is going to be broken in some sense. The code author will disagree in "a few" cases, and in those cases they will use repr=False to override.
I grant that there may be many reasons why one would be deriving dataclasses from dataclasses without adding fields that should be in the repr, so the quote marks above may be taken to be indications of my lack of imagination. ;-)
Here's to 2018. It has to be better than 2017 -- there will be a Python feature release!
Steve
- 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 ]