Eric V. Smith <e...@trueblade.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33539>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to