> > On 12/12/2019 8:07 AM, Arthur Pastel wrote: > > On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith <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_init__ so __setattr__ can check >>> it? >>> I don't want to add attributes that weren't defined in the class >>> definition. >>> >> Would it be okay if we create an instance attribute before calling the >> __init__ and then we remove it after the __post_init__ ? >> Then we would simply have to check for the attribute existence when >> checking if we raise a FrozenInstanceError. >> >> That wouldn't work if the class used __slots__. >> > > Then, in this specific case, would it be possible to add the attribute to > the __slots__ in the generated class ? > > No, __slots__ can't be added or modified after the class exists (which is > why @dataclass doesn't have an option to add __slots__). >
Arg, okay i didn't know. Then would it be possible to return a child class in the _process_class function ? It would then be possible to modify the slots. I'm trying to find a way around this but maybe this is not the good approach. On Thu, Dec 12, 2019 at 2:30 PM Eric V. Smith <e...@trueblade.com> wrote: > On 12/12/2019 8:07 AM, Arthur Pastel wrote: > > On Thu, Dec 12, 2019 at 2:03 AM Eric V. Smith <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_init__ so __setattr__ can check >>> it? >>> I don't want to add attributes that weren't defined in the class >>> definition. >>> >> Would it be okay if we create an instance attribute before calling the >> __init__ and then we remove it after the __post_init__ ? >> Then we would simply have to check for the attribute existence when >> checking if we raise a FrozenInstanceError. >> >> That wouldn't work if the class used __slots__. >> > > Then, in this specific case, would it be possible to add the attribute to > the __slots__ in the generated class ? > > No, __slots__ can't be added or modified after the class exists (which is > why @dataclass doesn't have an option to add __slots__). > > Eric > > >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UIRVAML5NIUQFEH76UIBJAWMKNDQVXTR/ Code of Conduct: http://python.org/psf/codeofconduct/