Barry A. Warsaw <[email protected]> added the comment:
On May 16, 2018, at 16:09, Eric V. Smith <[email protected]> wrote:
>
> I think the concern is:
>
> from dataclasses import *
>
> class B:
> def __init__(self, a, b, c):
> # do something with a, b, c, and maybe use fields(self) to figure out
> we have a "i" field
> self.i = a + b + c
>
> @dataclass(init=False)
> class C(B)
> i: int
>
> c = C(1, 2, 3)
>
> It doesn't seem particularly likely, but do we want to prevent it?
What are the intended semantics of this? I know what happens; c.i == 6
So, if I remove `init=False` and add an explicit __init__(), the same thing
still happens. Is that good enough?
from dataclasses import *
class B:
def __init__(self, a, b, c):
# do something with a, b, c, and maybe use fields(self) to figure out we
# have a "i" field
self.i = a + b + c
@dataclass
class C(B):
i: int
def __init__(self, a, b, c):
super().__init__(a, b, c)
c = C(1, 2, 3)
(Or maybe it’s the “use fields(self)” bit that you’re pointing out?)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33539>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com