PyDocs

Nav

Python Runtime Services

call_annotate_function

annotationlib

function · Added in 3.14 (source)
  • call_annotate_function(annotate, format, *, owner=None)
Call an __annotate__ function. __annotate__ functions are normally
generated by the compiler to defer the evaluation of annotations. They
can be called with any of the format arguments in the Format enum, but
compiler-generated __annotate__ functions only support the VALUE format.
This function provides additional functionality to call __annotate__
functions with the FORWARDREF and STRING formats.

*annotate* must be an __annotate__ function, which takes a single argument
and returns a dict of annotations.

*format* must be a member of the Format enum or one of the corresponding
integer values.

*owner* can be the object that owns the annotations (i.e., the module,
class, or function that the __annotate__ function derives from). With the
FORWARDREF format, it is used to provide better evaluation capabilities
on the generated ForwardRef objects.
1 Example
>>> from annotationlib import call_annotate_function, Format
>>> call_annotate_function(Annotate(), format=Format.STRING)
{'x': 'MyType'}
from the Python docs
See Also
No see-alsos for annotationlib/call_annotate_function
0 Notes
No notes for call_annotate_function