Guido van Rossum <gu...@python.org> added the comment:
Functions don't store __annotations__ in their __dict__, it is a separate slot named func_annotations (see funcobject.c). I guess that's because the __dict__ is purely for user-defined function attributes. But perhaps for classes the C equivalent of this pseudo-code will work? @property def __annotations__(self): if "__annotations__" not in self.__dict__: self.__dict__["__annotations__"] = {} return self.__dict__["__annotations__"] The whole thing is protected by the GIL of course, so there's no race condition between the check and the assignment. So if you look in __dict__ it will be like it's still Python 3.9, but if you're using the attribute (the recommended approach for code that only cares about 3.10) it'll be as if it always existed. Sounds pretty compatible to me. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43901> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com