[Python-ideas] Re: Should dataclass init call super?

2020-04-16 Thread Christopher Barker
On Wed, Apr 15, 2020 at 3:36 PM Eric V. Smith wrote: > In general, it's not possible to know how to call super.__init__() if you > don't a priori know the arguments it takes. That's why dataclasses doesn't > guess. The only general-purpose way to do it is to use *args and **kwargs. > I was

[Python-ideas] Re: Should dataclass init call super?

2020-04-16 Thread Eric V. Smith
On 4/14/2020 7:34 PM, Christopher Barker wrote: On Mon, Apr 13, 2020 at 9:22 PM Neil Girdhar > wrote: Cool, thanks for doing the relevant research. For my part, I'd like to see an aeefort to move dataclasses forward. Now that they are in the standard

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Eric V. Smith
On 4/15/2020 1:52 PM, Ricky Teachey wrote: Therefore, it seems weird for __init__ not to call super. I was not part of it, but I know this was heavily discussed during the development of dataclasses prior to 3.7, and it was decided not to do this, at least at THAT time (not saying that

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Joao S. O. Bueno
Scanning the messages, I met this from Ricky Teachey: I did write a decorator of my own that replaces the dataclass init with one > that calls super().__init__(*args, **kwargs) first before proceeding with > the one written by dataclasses... I can't find it at the moment. But that > has its own

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Joao S. O. Bueno
There is a way to have dataclasses as they are now behave collaboratively with a further decorator. For Python 3.8 livefcycle such decorator could live in an external package - if its good, it could go into the stdlib, or maybe, another "dataclasses.collaborative_dataclass" would already create

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Andrew Barnert via Python-ideas
On Apr 15, 2020, at 10:16, Brett Cannon wrote: > > >> On Wed, Apr 15, 2020 at 8:45 AM Christopher Barker >> wrote: >> > you'd just add *args and **kwargs to the init signature and call >> > super().__init__(*args, **kwargs). >>> >>> Which is what the OP is after. >> >> Hmm, makes me

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Ricky Teachey
> I think ultimately the argument you want to make really is the > “enlightened laziness” one: there are lots of optional Pandas-y parameters > in your superclass(es), and most of them you will definitely never care > about, but a few of them you actually might occasionally care about. What >

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Andrew Barnert via Python-ideas
> On Apr 15, 2020, at 10:48, Ricky Teachey wrote: >  >>> It becomes more painful the more parameters the parent has- parameters >>> which the dataclass may not even care about. It not only makes the class >>> definition long, it adds so these additional parameters to the init >>> signature,

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Ricky Teachey
> > Therefore, it seems weird for __init__ not to call super. > I was not part of it, but I know this was heavily discussed during the development of dataclasses prior to 3.7, and it was decided not to do this, at least at THAT time (not saying that can't change, but there were reasons). If Eric

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Ricky Teachey
> > It becomes more painful the more parameters the parent has- parameters > which the dataclass may not even care about. It not only makes the class > definition long, it adds so these additional parameters to the init > signature, which is icky for introspection and discoverability. Lots of >

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Neil Girdhar
I'm just curious: what is the downside of calling super with kwargs? Usually when I define a class, the first I write is def __init__(self, **kwargs): super().__init__(**kwargs) just in case I want to use the class in cooperative inheritance. I always thought it couldn't hurt? I might be

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Andrew Barnert via Python-ideas
> On Apr 15, 2020, at 04:26, Ricky Teachey wrote: >  For simple situations you can call super in the __post_init__ method and things will work fine: >>> >>> But not for the OP's case: he wanted to pass extra parameters in -- and the >>> dataclass' __init__ won't accept extra

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Brett Cannon
On Wed, Apr 15, 2020 at 8:45 AM Christopher Barker wrote: > > you'd just add *args and **kwargs to the init signature and call > super().__init__(*args, **kwargs). > >> >> Which is what the OP is after. >> > > Hmm, makes me wonder if there should be an option to define a __pre_init__ > method. >

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Christopher Barker
> you'd just add *args and **kwargs to the init signature and call super().__init__(*args, **kwargs). > > Which is what the OP is after. > Hmm, makes me wonder if there should be an option to define a __pre_init__ method. Then you could customize the signature, but still use data classes nifty

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Ricky Teachey
> > For simple situations you can call super in the __post_init__ method and >> things will work fine: >> > > But not for the OP's case: he wanted to pass extra parameters in -- and > the dataclass' __init__ won't accept extra arguments. > > > Can’t you just create InitVar attributes for the extra

[Python-ideas] Re: Should dataclass init call super?

2020-04-15 Thread Andrew Barnert via Python-ideas
On Apr 14, 2020, at 20:53, Christopher Barker wrote: > >> On Tue, Apr 14, 2020 at 7:46 PM Ricky Teachey wrote: >> For simple situations you can call super in the __post_init__ method and >> things will work fine: > > But not for the OP's case: he wanted to pass extra parameters in -- and the

[Python-ideas] Re: Should dataclass init call super?

2020-04-14 Thread Christopher Barker
On Tue, Apr 14, 2020 at 7:46 PM Ricky Teachey wrote: > For simple situations you can call super in the __post_init__ method and > things will work fine: > But not for the OP's case: he wanted to pass extra parameters in -- and the dataclass' __init__ won't accept extra arguments. -CHB >

[Python-ideas] Re: Should dataclass init call super?

2020-04-14 Thread Wes Turner
Could there be a self.super that defaults to true; but could be set to a callable? On Tue, Apr 14, 2020, 10:47 PM Ricky Teachey wrote: > For simple situations you can call super in the __post_init__ method and > things will work fine: > > class BaseClass: > def __init__(self): >

[Python-ideas] Re: Should dataclass init call super?

2020-04-14 Thread Ricky Teachey
For simple situations you can call super in the __post_init__ method and things will work fine: class BaseClass: def __init__(self): print("class BaseClass") @dataclass class DataClass(BaseClass): def __post_init__(self): super().__init__() print("class

[Python-ideas] Re: Should dataclass init call super?

2020-04-14 Thread Christopher Barker
On Mon, Apr 13, 2020 at 9:22 PM Neil Girdhar wrote: > Cool, thanks for doing the relevant research. > For my part, I'd like to see an aeefort to move dataclasses forward. Now that they are in the standard library, they do need to remain pretty stable, but there's still room for extending them.