bpo-43987: Add "Annotations Best Practices" HOWTO doc. (#25746)

Add "Annotations Best Practices" HOWTO doc.
This commit is contained in:
larryhastings 2021-05-01 21:19:24 -07:00 committed by GitHub
parent 318ca1764c
commit 49b26fa517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 298 additions and 21 deletions

View file

@ -807,7 +807,9 @@ Other Language Changes
* Class and module objects now lazy-create empty annotations dicts on demand.
The annotations dicts are stored in the objects ``__dict__`` for
backwards compatibility.
backwards compatibility. This improves the best practices for working
with ``__annotations__``; for more information, please see
:ref:`annotations-howto`.
(Contributed by Larry Hastings in :issue:`43901`.)
New Modules
@ -996,7 +998,9 @@ defined on an object. It works around the quirks of accessing the annotations
on various types of objects, and makes very few assumptions about the object
it examines. :func:`inspect.get_annotations` can also correctly un-stringize
stringized annotations. :func:`inspect.get_annotations` is now considered
best practice for accessing the annotations dict defined on any Python object.
best practice for accessing the annotations dict defined on any Python object;
for more information on best practices for working with annotations, please see
:ref:`annotations-howto`.
Relatedly, :func:`inspect.signature`,
:func:`inspect.Signature.from_callable`, and ``inspect.Signature.from_function``
now call :func:`inspect.get_annotations` to retrieve annotations. This means