[issue43835] Dataclasses don't call base class __init__

2021-04-16 Thread Terry J. Reedy
Change by Terry J. Reedy : -- versions: -Python 3.7 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Eric V. Smith
Change by Eric V. Smith : -- assignee: -> eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:/

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Eric V. Smith
Eric V. Smith added the comment: Yes, I'm sure it happens. from dataclasses import dataclass @dataclass class Foo: foo: int def __init__(self, a, b, c): self.foo = a * b * c @dataclass class Bar(Foo): bar: int print(Bar(1, 2)) print(Foo(1, 2, 3)) -- _

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Paul Pinterits
Paul Pinterits added the comment: You're telling me that some people out there rely on their custom __init__ *not* being called? O.o -- ___ Python tracker ___ ___

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Eric V. Smith
Eric V. Smith added the comment: But Bar(1, 2), Bar(1, foo=2), Bar(bar=1, foo=2) all give errors. These are all valid if both Foo and Bar are decorated with @dataclass. Calling base class __init__() functions is an incompatible change, and I don't think we'll make any change to do so. -

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Paul Pinterits
Paul Pinterits added the comment: Admittedly, with the way dataclasses accept their __init__ arguments, figuring out which arguments to consume and which to pass on isn't a trivial task. If a dataclass Bar inherits from a dataclass Foo, then Bar.__init__ is (for all intents and purposes) def

[issue43835] Dataclasses don't call base class __init__

2021-04-14 Thread Paul Pinterits
Paul Pinterits added the comment: No, I'm saying Bar should initialize the 'bar' attribute, and then call Foo.__init__ to let it initialize the 'foo' attribute. -- ___ Python tracker ___

[issue43835] Dataclasses don't call base class __init__

2021-04-13 Thread Eric V. Smith
Eric V. Smith added the comment: > The dataclass doesn't need to know what arguments the parent __init__ > accepts. It should consume the arguments it needs to initialize its instance > attributes, and forward the rest to the parent __init__. The generated __init__() uses every parameter to

[issue43835] Dataclasses don't call base class __init__

2021-04-13 Thread Paul Pinterits
Paul Pinterits added the comment: > dataclasses doesn't know the signature of the base class's __init__, so it > can't know how to call it. The dataclass doesn't need to know what arguments the parent __init__ accepts. It should consume the arguments it needs to initialize its instance attri

[issue43835] Dataclasses don't call base class __init__

2021-04-13 Thread Eric V. Smith
Eric V. Smith added the comment: dataclasses doesn't know the signature of the base class's __init__, so it can't know how to call it. I realize you've given an example that would accept any parameters, but that isn't typical. What if the base class was: @dataclasses.dataclass class Foo:

[issue43835] Dataclasses don't call base class __init__

2021-04-13 Thread Paul Pinterits
New submission from Paul Pinterits : It's documented behavior that @dataclass won't generate an __init__ method if the class already defines one. It's also documented that a dataclass may inherit from another dataclass. But what happens if you inherit from a dataclass that implements a custom