MCPcopy
hub / github.com/tortoise/tortoise-orm / get_annotations

Function get_annotations

tortoise/contrib/pydantic/utils.py:10–34  ·  view source on GitHub ↗

Get all annotations including base classes. Builds a namespace from the Tortoise apps registry so that forward references (string annotations) to models defined in other files can be resolved by :func:`typing.get_type_hints`. :param cls: The model class we need annotations fro

(cls: type[Model], method: Callable | None = None)

Source from the content-addressed store, hash-verified

8
9
10def get_annotations(cls: type[Model], method: Callable | None = None) -> dict[str, Any]:
11 """
12 Get all annotations including base classes.
13
14 Builds a namespace from the Tortoise apps registry so that forward references
15 (string annotations) to models defined in other files can be resolved by
16 :func:`typing.get_type_hints`.
17
18 :param cls: The model class we need annotations from
19 :param method: If specified, we try to get the annotations for the callable
20 :return: The list of annotations
21 """
22 localns: dict[str, Any] = {}
23 try:
24 from tortoise import Tortoise
25
26 if Tortoise.apps:
27 for app_models in Tortoise.apps.values():
28 localns.update(app_models)
29 except Exception: # nosec B110
30 pass
31 try:
32 return get_type_hints(method or cls, localns=localns)
33 except Exception:
34 return getattr(method or cls, "__annotations__", {})

Callers 2

__init__Method · 0.90

Calls 2

updateMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…