On Wed, 13 Jan 2021, 12:35 pm Larry Hastings, <la...@hastings.org> wrote:
> > On 1/12/21 5:28 PM, Brett Cannon wrote: > > The other thing to keep in mind is we are talking about every module, > class, and function getting 64 bytes ... which I bet isn't that much. > > Actually it's only every module and class. Functions don't have this > problem because they've always stored __annotations__ internally--meaning, > peeking in their __dict__ doesn't work, and they don't support inheritance > anyway. So the number is even smaller than that. > > If we can just make __annotations__ default to an empty dict on classes > and modules, and not worry about the memory consumption, that goes a long > way to cleaning up the semantics. > Could you get the best of both worlds by making __annotations__ an auto-populating descriptor on "type", the way it is on functions? Continue to add a non-empty annotations dict to the class dict eagerly, but only add the empty dict when "cls.__annotations__" is accessed. Then your co_annotations PEP would only be changing the way the non-empty case was handled, rather than introducing the descriptor in the first place. Cheers, Nick. >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/BMBFLLQZY4WZP5RQ32OFQYR2N3UMHTFF/ Code of Conduct: http://python.org/psf/codeofconduct/