Skip to content

Commit 0c7fefc

Browse files
committed
Extend the listing of how the formats work
1 parent 63e4bc9 commit 0c7fefc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Doc/library/annotationlib.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,29 @@ Functions
340340

341341
* VALUE: :attr:`!object.__annotations__` is tried first; if that does not exist,
342342
the :attr:`!object.__annotate__` function is called if it exists.
343+
343344
* FORWARDREF: If :attr:`!object.__annotations__` exists and can be evaluated successfully,
344345
it is used; otherwise, the :attr:`!object.__annotate__` function is called. If it
345346
does not exist either, :attr:`!object.__annotations__` is tried again and any error
346347
from accessing it is re-raised.
348+
349+
* When calling :attr:`!object.__annotate__` it is first called with :attr:`~Format.FORWARDREF`,
350+
if this is not implemented it will then check if :attr:`~Format.VALUE_WITH_FAKE_GLOBALS`
351+
is supported and use that in the fake globals environment.
352+
If neither of these formats are supported it will fall back to using :attr:`~Format.VALUE`.
353+
If :attr:`~Format.VALUE` fails, the error from this call will be raised.
354+
347355
* STRING: If :attr:`!object.__annotate__` exists, it is called first;
348356
otherwise, :attr:`!object.__annotations__` is used and stringified
349357
using :func:`annotations_to_string`.
350358

359+
* When calling :attr:`!object.__annotate__` it is first called with :attr:`~Format.STRING`,
360+
if this is not implemented it will then check if :attr:`~Format.VALUE_WITH_FAKE_GLOBALS`
361+
is supported and use that in the fake globals environment.
362+
If neither of these formats are supported it will fall back to using :attr:`~Format.VALUE`
363+
with the result converted using :func:`annotations_to_string`.
364+
If :attr:`~Format.VALUE` fails, the error from this call will be raised.
365+
351366
Returns a dict. :func:`!get_annotations` returns a new dict every time
352367
it's called; calling it twice on the same object will return two
353368
different but equivalent dicts.

0 commit comments

Comments
 (0)