<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
<div>I'm not a typing expert, but I want to second Raymond's concerns, and perhaps I'm qualified to do so as I gave the PyCon USA __slots__ talk this year and I have a highly voted answer describing them on Stack Overflow.</div><div><br></div><div>Beautiful thing we're doing here with the dataclasses, by the way. I think addressing the slots issue could be a killer feature of dataclasses.<br></div><div><div><br></div><div>I hope this doesn't muddy the water:<br></div><div><br></div></div><div>If I could change a couple of things about __slots__ it would be </div><div>1. to allow multiple inheritance with multiple parents with nonempty slots (raises "TypeError: multiple bases have instance lay-out conflict"), and<br></div><div>2. to avoid creating redundant slots if extant in a parent (but maybe we should do this in the C level for all classes?).<br></div><div><br></div><div>It seems to me that Dataclasses could (and should) help us avoid the second issue regardless (should be trivial to look in the bases for preexisting slots, right?).<br></div><div><br></div><div>My workaround for the first issue is to inherit from ABCs with empty slots, but you
need cooperative multiple inheritance for this - and you need to track
the expected attributes (easy if you use abstract properties, which slots provide for. Maybe not all users of Dataclasses are advanced enough to do this?<br></div><div><br></div><div>So, maybe this is crazy (please don't call the nice men in white coats on me), came to me as I was responding, and definitely outside the box here, but perhaps we could make decorated dataclass be the abstract parent of the instantiated class?<br></div><div><br></div><div>Thanks,</div><div><br></div><div>Aaron Hall<br></div><div><br></div>
<div id="ydpd14031fayahoo_quoted_3724713816" class="ydpd14031fayahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Friday, December 8, 2017, 1:31:44 PM EST, Raymond Hettinger <raymond.hettinger@gmail.com> wrote:
</div>
<div><br></div>
<div><div dir="ltr">The way __slots__ works is that the type() metaclass automatically assigns member-objects to the class variables 'x' and 'y'. Member objects are descriptors that do the actual lookup.<br clear="none"><br clear="none">So, I don't think the language limitation can be "fixed". Essentially, we're wanting to use the class variables 'x' and 'y' to hold both member objects and a default value.<br clear="none"><br clear="none">I recommend that you follow the path taken by attrs and return a new class. Otherwise, we're leaving users with a devil's choice. You can have default values or you can have slots, but you can't have both.<br clear="none"><br clear="none">The slots are pretty important. With slots, a three attribute instance is only 64 bytes. Without slots, it is 296 bytes.<br clear="none"><br clear="none">I'm hoping the typing experts will chime in here. The question is straight-forward. Where should we look for the signature and docstring for constructing instances? Should they be attached to the class, to __init__(), or to __new__() when it used.<br clear="none"><br clear="none">It would be nice to have an official position on that before, it gets set in stone through arbitrary choices made by pycharm, pydoc, mypy, typing.NamedTuple, and dataclasses.dataclass.<div class="ydpd14031fayqt4413251211" id="ydpd14031fayqtfd08272"><br clear="none"><br clear="none"><br clear="none">Raymond<br clear="none"><br clear="none"><br clear="none"><br clear="none"><br clear="none">_______________________________________________<br clear="none">Python-Dev mailing list<br clear="none"><a shape="rect" href="mailto:Python-Dev@python.org" rel="nofollow" target="_blank">Python-Dev@python.org</a><br clear="none"><a shape="rect" href="https://mail.python.org/mailman/listinfo/python-dev" rel="nofollow" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br clear="none">Unsubscribe: <a shape="rect" href="https://mail.python.org/mailman/options/python-dev/aaronchall%40yahoo.com" rel="nofollow" target="_blank">https://mail.python.org/mailman/options/python-dev/aaronchall%40yahoo.com</a><br clear="none"></div></div></div>
</div>
</div></div></body></html>