This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients eric.smith, gvanrossum, larry
Date 2021-04-21.23:14:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619046866.75.0.0978538925961.issue43901@roundup.psfhosted.org>
In-reply-to
Content
It occurs to me that part of this work should also be a new "best practices for __annotations__" entry in the Python docs.


Best practices for working with annotations, for code that requires a minimum Python version of 3.10+:

Best practice is to call either inspect.get_annotations() or typing.get_type_hints() to access annotations.  But if you want to access '__annotations__' on an object directly:

* Always access the annotations on an object using the attribute interface, either o.__annotations__ or getattr(o, '__annotations__').  Accessing '__annotations__' through other mechanisms (e.g. looking in the class dict) is unsupported.
* Assume that o.__annotations__ is always either a dict or None.
* It's best to not assign to o.__annotations__.  But if you must, always set it to either a dict or None.
* Never delete o.__annotations__.
* Never modify o.__annotations__.
History
Date User Action Args
2021-04-21 23:14:26larrysetrecipients: + larry, gvanrossum, eric.smith
2021-04-21 23:14:26larrysetmessageid: <1619046866.75.0.0978538925961.issue43901@roundup.psfhosted.org>
2021-04-21 23:14:26larrylinkissue43901 messages
2021-04-21 23:14:26larrycreate