annotationlib.get_annotations
Prev: annotationlib.get_annotate_from_class_namespace | Up: annotationlib | Next: annotationlib.type_repr
Rel: annotationlib.annotations_to_string, annotationlib.call_annotate_function, annotationlib.call_evaluate_function, annotationlib.Format
Ref: docs.python.org — annotationlib.get_annotations
Tags: #public #python3 #stdlib #annotationlib
Import
import annotationlib
from annotationlib import get_annotations
Signature & Overview
annotationlib.get_annotations(obj, *, globals=None, locals=None, eval_str=False, format=<Format.VALUE: 1>)
Compute the annotations dict for an object.
Usage
import annotationlib
def add(a: int, b: int) -> int: return a + b
assert annotationlib.get_annotations(add, format=annotationlib.Format.VALUE) == {"a": int, "b": int, "return": int}
Gotchas
- Requires Python 3.14+: Replaces
inspect.get_annotations()with full PEP 649Format.VALUE/FORWARDREF/STRINGsupport.
REPL Inspect
from annotationlib import get_annotations
help(get_annotations)
Linked from
Related notes
- tuts/python3/stdlib_module/annotationlib/get_annotate_from_class_namespace Linked here; links to this page; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/type_repr 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/annotations_to_string Linked here; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/call_annotate_function Linked here; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/call_evaluate_function Linked here; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/Format Linked here; shared tags: #annotationlib, #stdlib
- tuts/python3/stdlib_module/annotationlib/ForwardRef shared tags: #annotationlib, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib