Message316865
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. |
|
Date |
User |
Action |
Args |
2018-05-16 20:48:40 | eric.smith | set | recipients:
+ eric.smith, gvanrossum, barry, ned.deily |
2018-05-16 20:48:40 | eric.smith | set | messageid: <1526503720.38.0.682650639539.issue33539@psf.upfronthosting.co.za> |
2018-05-16 20:48:40 | eric.smith | link | issue33539 messages |
2018-05-16 20:48:40 | eric.smith | create | |
|