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 barry, eric.smith, gvanrossum, ned.deily
Date 2018-05-16.20:48:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526503720.38.0.682650639539.issue33539@psf.upfronthosting.co.za>
In-reply-to
Content
The concern is that you've created an awesome base class, and you've written 500 dataclasses that are derived from it, but you want to use the base class's __init__ for all 500. Do you really want to add a __init__ to each of the 500 classes? We're trying to reduce boilerplate!

Again, I'm not saying it's likely.

The comment about fields(self) is meant to say that they could be inspecting the derived class to figure out which field to set. Something like:

class B:
    def __init__(self, a, b, c):
        first_field = next(iter(fields(self)))
        setattr(self, first_field.name, a+b+c)

mydataclass = dataclass(init=False)

@mydataclass
class C(B):
    i: int

@mydataclass
class D(B):
    j: int

print(C(1, 2, 3))
print(D(4, 5, 6))

produces:
C(i=6)
D(j=15)

That is, the base class could legitimately being doing something with the derived class fields, and you might want to move all of the logic in to a base class.
History
Date User Action Args
2018-05-16 20:48:40eric.smithsetrecipients: + eric.smith, gvanrossum, barry, ned.deily
2018-05-16 20:48:40eric.smithsetmessageid: <1526503720.38.0.682650639539.issue33539@psf.upfronthosting.co.za>
2018-05-16 20:48:40eric.smithlinkissue33539 messages
2018-05-16 20:48:40eric.smithcreate