MCPcopy Index your code
hub / github.com/RustPython/RustPython / _get_dunder_annotations

Function _get_dunder_annotations

Lib/annotationlib.py:1131–1152  ·  view source on GitHub ↗

Return the annotations for an object, checking that it is a dictionary. Does not return a fresh dictionary.

(obj)

Source from the content-addressed store, hash-verified

1129
1130
1131def _get_dunder_annotations(obj):
1132 """Return the annotations for an object, checking that it is a dictionary.
1133
1134 Does not return a fresh dictionary.
1135 """
1136 # This special case is needed to support types defined under
1137 # from __future__ import annotations, where accessing the __annotations__
1138 # attribute directly might return annotations for the wrong class.
1139 if isinstance(obj, type):
1140 try:
1141 ann = _BASE_GET_ANNOTATIONS(obj)
1142 except AttributeError:
1143 # For static types, the descriptor raises AttributeError.
1144 return None
1145 else:
1146 ann = getattr(obj, "__annotations__", None)
1147 if ann is None:
1148 return None
1149
1150 if not isinstance(ann, dict):
1151 raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None")
1152 return ann

Callers 1

get_annotationsFunction · 0.85

Calls 2

isinstanceFunction · 0.85
getattrFunction · 0.85

Tested by

no test coverage detected