[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-13 Thread Barry
> On 13 Dec 2019, at 14:57, Arthur Pastel wrote: > >  >> I think the simpler route to go there (allow the use of `self.attr=` until >> after ___post_init__ is run is simply >> to add another flag attribute, that tells wether "initialization is over", >> and respect that flag > > > We discu

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-13 Thread Arthur Pastel
> > I think the simpler route to go there (allow the use of `self.attr=` until > after ___post_init__ is run is simply > to add another flag attribute, that tells wether "initialization is over", > and respect that flag > We discussed this just before and having an extra instance attribute was qu

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-13 Thread Joao S. O. Bueno
I think the simpler route to go there (allow the use of `self.attr=` until after ___post_init__ is run is simply to add another flag attribute, that tells wether "initialization is over", and respect that flag in the added `__setattr__`. The hook calling `__post_init__` would then set that flag aft

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-13 Thread Arthur Pastel
On Thu, Dec 12, 2019 at 4:37 PM Eric V. Smith wrote: > On 12/12/2019 8:50 AM, Arthur Pastel wrote: > > On 12/12/2019 8:07 AM, Arthur Pastel wrote: >> >> On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith wrote: >>> On 12/11/2019 6:36 PM, Arthur Pastel wrote: >> Add an extra hidden attribute

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Eric V. Smith
On 12/12/2019 8:50 AM, Arthur Pastel wrote: On 12/12/2019 8:07 AM, Arthur Pastel wrote: On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith mailto:e...@trueblade.com>> wrote: On 12/11/2019 6:36 PM, Arthur Pastel wrote: >> Add an extra hidden attribute to

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Arthur Pastel
> > On 12/12/2019 8:07 AM, Arthur Pastel wrote: > > On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith wrote: >> >>> On 12/11/2019 6:36 PM, Arthur Pastel wrote: >>> >> Add an extra hidden attribute to every instance just >>> >> to track whether you’re inside __post_init__ so __setattr__ can check >>> i

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Eric V. Smith
On 12/12/2019 8:07 AM, Arthur Pastel wrote: On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith mailto:e...@trueblade.com>> wrote: On 12/11/2019 6:36 PM, Arthur Pastel wrote: >> Add an extra hidden attribute to every instance just >> to track whether you’re inside __post_

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Arthur Pastel
> > On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith wrote: > >> On 12/11/2019 6:36 PM, Arthur Pastel wrote: >> >> Add an extra hidden attribute to every instance just >> >> to track whether you’re inside __post_init__ so __setattr__ can check >> it? >> I don't want to add attributes that weren't def

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Eric V. Smith
On 12/12/2019 5:05 AM, Arthur Pastel wrote: On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith > wrote: On 12/11/2019 6:36 PM, Arthur Pastel wrote: >> Add an extra hidden attribute to every instance just >> to track whether you’re inside __post_init__ so __setat

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-12 Thread Arthur Pastel
On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith wrote: > On 12/11/2019 6:36 PM, Arthur Pastel wrote: > >> Add an extra hidden attribute to every instance just > >> to track whether you’re inside __post_init__ so __setattr__ can check > it? > I don't want to add attributes that weren't defined in th

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Arthur Pastel
Otherwise, maybe it could be possible to rewrite assignment done in __post_init__ . However, I'm not sure that it will be generic enough. Arthur Pastel, On Thu, Dec 12, 2019 at 1:10 AM Andrew Barnert wrote: > On Dec 11, 2019, at 15:40, Arthur Pastel wrote: > > > >> If dataclass handled freeze

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Eric V. Smith
On 12/11/2019 6:36 PM, Arthur Pastel wrote: If dataclass handled freezeable types (the objects are mutable until you call freeze, after which they’re not), this would be easy (frozen now just means freezable, plus freeze is called by the generated __init__ right after the __post_init__). But it

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
On Dec 11, 2019, at 15:40, Arthur Pastel wrote: > >> If dataclass handled freezeable types (the objects are mutable until you >> call freeze, >> after which they’re not), this would be easy (frozen now just means >> freezable, plus freeze >> is called by the generated __init__ right after the _

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
On Dec 11, 2019, at 15:10, Ricky Teachey wrote: > >  > bah, I forgot the underscore in the setter. Corrected for clarity: > > @dataclasses.dataclass(frozen=True) > class Person: > name: str > surname: str > fullname: str = dataclasses.field(property=True) # fullname is now a > fie

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Arthur Pastel
> If dataclass handled freezeable types (the objects are mutable until you call > freeze, > after which they’re not), this would be easy (frozen now just means > freezable, plus freeze > is called by the generated __init__ right after the __post_init__). But it > doesn’t, > because freezing is c

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Ricky Teachey
bah, I forgot the underscore in the setter. Corrected for clarity: @dataclasses.dataclass(frozen=True) class Person: name: str surname: str fullname: str = dataclasses.field(property=True) # fullname is now a field descriptor @fullname.getter def fullname_getter(self):

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Ricky Teachey
> I agree with Andrew: it's a great idea, but I couldn't come up with a > way to implement it, so I followed attrs lead instead. Maybe someone can > come up with a good way to implement it It seems like this could be solved if a general way could be created to allow dataclasses to handle descript

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Eric V. Smith
On 12/11/2019 1:23 PM, Andrew Barnert via Python-ideas wrote: On Dec 11, 2019, at 08:56, Arthur Pastel wrote: When creating frozen dataclasses, attribute initialization must be done using `object.__setattr__()` it would be nice to allow attribute assignment in the `__init__` and `__post_init

[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-11 Thread Andrew Barnert via Python-ideas
On Dec 11, 2019, at 08:56, Arthur Pastel wrote: > > When creating frozen dataclasses, attribute initialization must be done > using `object.__setattr__()` it would be nice to allow attribute assignment > in the `__init__` and `__post_init__`. But how would you implement that? Frozen means th