[Python-ideas] Re: frozen dataclasses attribute initialization

2019-12-13 Thread Arthur Pastel
7;super(cls, self).__delattr__(name)'), >globals=globals), > (END) > ``` > > To get it working for `__init__` as well, however is a bit more > complicated - as we > don't have control of the dataclass metaclass, the only way to put a hook > to

[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

[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 whe

[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? &

[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 at

[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: > > > >&g

[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] frozen dataclasses attribute initialization

2019-12-11 Thread Arthur Pastel
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__`. Currently we have to do this : ```python @dataclasses.dataclass(frozen=True) class Person: name: str