On this page
annotationlib.call_annotate_function
Prev: annotationlib.annotations_to_string | Up: annotationlib | Next: annotationlib.call_evaluate_function
Rel: annotationlib.annotations_to_string, annotationlib.call_evaluate_function, annotationlib.Format, annotationlib.ForwardRef
Ref: docs.python.org — annotationlib.call_annotate_function
Tags: #public #python3 #stdlib #annotationlib
Import
import annotationlib
from annotationlib import call_annotate_function
Signature & Overview
annotationlib.call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False)
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
Usage
import annotationlib
def fn(x: int) -> str: return str(x)
ann = annotationlib.call_annotate_function(fn.__annotate__, annotationlib.Format.VALUE)
assert ann == {"x": int, "return": str}
Gotchas
- Requires Python 3.14+: Prefer
annotationlib.get_annotations(obj, format=...)unless directly invoking a custom__annotate__function.
REPL Inspect
from annotationlib import call_annotate_function
help(call_annotate_function)
Linked from
- tuts/python3/stdlib_module/annotationlib
- tuts/python3/stdlib_module/annotationlib/annotations_to_string
- tuts/python3/stdlib_module/annotationlib/call_evaluate_function
- tuts/python3/stdlib_module/annotationlib/Format
- tuts/python3/stdlib_module/annotationlib/ForwardRef
- tuts/python3/stdlib_module/annotationlib/get_annotate_from_class_namespace
- tuts/python3/stdlib_module/annotationlib/get_annotations
- tuts/python3/stdlib_module/annotationlib/type_repr
Related notes
- tuts/python3/stdlib_module/annotationlib/annotations_to_string Linked here; links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/call_evaluate_function Linked here; links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/Format Linked here; links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/ForwardRef Linked here; links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/annotationlib/get_annotate_from_class_namespace links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/get_annotations links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/type_repr links to this page; shared tags: #annotationlib, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib