Re: [Python-Dev] Dataclasses, frozen and __post_init__

2018-02-17 Thread Guido van Rossum
Agreed the __pre_init__ idea is no improvement. I think we're back where you started -- just use `object.__setattr__` to set the attribute in `__post_init__`. That's what the PEP says is used by the generated `__init__`, so I think it is reasonable to copy that pattern. Presumably the situation doe

Re: [Python-Dev] Dataclasses, frozen and __post_init__

2018-02-17 Thread Ben Lewis
> > Why can'y you make `name` on `NamedObjectItem` a property that returns ` > self.obj.name`? Why store a duplicate copy of the name? > Agreed, it's probably a better design not to store a duplicate reference to name. But when I tried that, the property clashed with the inherited field. This caus

[Python-Dev] Replacement proposal for PEP 557 Data Classes

2018-02-17 Thread Ramazan POLAT
Hi, I have been working on a new way to use Python classes as enhanced dict object(I called it Prodict). My solution is (IMHO) more concise and brings more features. So I wanted to make it a PEP until I saw PEP 557 Data Classes. With my proposed enhancement, I can do everything Data Classes can do

Re: [Python-Dev] Dataclasses, frozen and __post_init__

2018-02-17 Thread Guido van Rossum
Why can'y you make `name` on `NamedObjectItem` a property that returns ` self.obj.name`? Why store a duplicate copy of the name? PS. I have to ponder why frozen dataclasses don't use `__new__`. On Fri, Feb 16, 2018 at 11:43 PM, Ben Lewis wrote: > On Sat, Feb 17, 2018 at 6:40 PM, Guido van Rossu

Re: [Python-Dev] Dataclasses, frozen and __post_init__

2018-02-17 Thread Ben Lewis
On Sat, Feb 17, 2018 at 6:40 PM, Guido van Rossum wrote: > > > That's a pretty tricky proposal, and one that's been debated on and off > for a long time in other contexts. And that flag would somehow have to be > part of every instance's state. > > In general the right way to initialize an immuta