MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / get_annotations

Function get_annotations

deepspeed/compat.py:31–47  ·  view source on GitHub ↗

Retrieves annotations from a Python object. In python >=3.14 this is a thin wrapper around the `annotationlib.get_annotations` function with the added convenience to automatically infer the type for non module, class, function or customly annotated objects.

(obj: Any)

Source from the content-addressed store, hash-verified

29
30
31def get_annotations(obj: Any) -> Dict[str, Any]:
32 """
33 Retrieves annotations from a Python object.
34
35 In python >=3.14 this is a thin wrapper around the `annotationlib.get_annotations` function
36 with the added convenience to automatically infer the type for non module, class, function
37 or customly annotated objects.
38 """
39 if annotationlib:
40 has_annotations = hasattr(obj, "__annotations__") or hasattr(obj, "__annotate__")
41 if not isinstance(obj, type) and not ismodule(obj) and not callable(obj) and not has_annotations:
42 obj = type(obj)
43 return annotationlib.get_annotations(obj)
44 try:
45 return obj.__annotations__
46 except AttributeError:
47 return {}

Callers 3

__new__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected