[issue43901] Add an empty annotations dict to all unannotated classes and modules

Larry Hastings report at bugs.python.org
Wed Apr 21 18:59:40 EDT 2021


Larry Hastings <larry at hastings.org> added the comment:

By the way, here's a tidbit I never got around to posting in c.l.p-d.

I noted in the conversation in January that attrs is an outlier here: it *doesn't* look in the class dict for __annotations__.  Instead, it has some complicated code where it asks the class for its annotations, then iterates over the __mro__ and asks every base class for *its* annotations.  If the class and a base class have the same class dict (using the "is" operator iirc) then attrs says "oh, that class doesn't have its own annotations, it's inheriting them" and reacts appropriately.

I emailed Hynek to ask him why he did it that way.  It turns out, he did that because at the time he didn't know you could peek in the class dict for __annotations__.  He literally had a todo item saying "change to looking in the class dict".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43901>
_______________________________________


More information about the Python-bugs-list mailing list