27.09.19 19:48, Andrew Barnert via Python-ideas пише:
On Friday, September 27, 2019, 07:47:41 AM PDT, Johnny Dahlberg
<svartchimp...@gmail.com> wrote:
> My proposal: Implement `@dataclass(slots=True)` which does the same
thing as attrs: Replaces the class with a modified class that has a
`__slots__` property instead of a `__dict__`. And fully supporting
default values in the process.
I don't think anyone would be against this in principle; the question is
implementing it, and bikeshedding. For example, if nobody's come up with
a better implementation than Eric's original one, should we add a
@dataclass_slots decorator, or a @slotsify that you put around
@dataclass, or get rid of the guarantee that @dataclass returns your
class with extra dunders.
IIRC, the consensus after the discussion at the time was that this was a
feature that could be added later, after a bit more experience in the
field (and maybe someone will come up with a better implementation by
then), so it was just deferred to the future rather than rejected.
Meanwhile, the @slotsify or @dataclass_slots should be writable as a
PyPI package. Has anyone done that? If there's a popular and stable
implementation, that's a good argument for merging it into the stdlib
(and leaving it on PyPI as a backport). If it turned out to be tricky to
implement without modifying dataclass itself, explaining why could also
be a good argument for moving it into the stdlib.
I think it needs an explicit support in the type creation machinery (as
__slots__ itself has) to support descriptors and slots with the same name.
It would be also useful for other applications, like cached_property.
_______________________________________________
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/TQWH6XAR7VQZ66IA2NF5OVX5Q3DM2ZUR/
Code of Conduct: http://python.org/psf/codeofconduct/