On 2019-09-28 03:12, Eric V. Smith wrote:
On Sep 27, 2019, at 8:23 PM, Guido van Rossum <guido@python.org> wrote:
On Fri, Sep 27, 2019 at 11:18 AM Serhiy Storchaka <storchaka@gmail.com <mailto:storchaka@gmail.com>> wrote:
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.
That would be tough, since __slots__ is currently implemented by creating a separate descriptor for each slot.
I do think that it would be nice to have a way to automatically create __slots__ from annotations. It would be even nicer if that could be done without copying the class object (as the current state of the art requires: https://github.com/ericvsmith/dataclasses/blob/master/dataclass_tools.py#L23).
Thinking aloud, perhaps this could be done by setting __slots__ to a magical value, e.g.
class Point: __slots__ = "__auto__" x: float y: float
I think a sentinel like None or a new typing.use_annotations_for_slots (need a better name, of course) would be better than a magic string, especially since strings are iterable.
[snip] I was also thinking about suggesting None, but I was wondering whether that could be misleading because it reads like "no slots". What about "..." instead? Would that read better? class Point: __slots__ = .... x: float y: float