Return the annotations for an object, checking that it is a dictionary. Does not return a fresh dictionary.
(obj)
| 1142 | |
| 1143 | |
| 1144 | def _get_dunder_annotations(obj): |
| 1145 | """Return the annotations for an object, checking that it is a dictionary. |
| 1146 | |
| 1147 | Does not return a fresh dictionary. |
| 1148 | """ |
| 1149 | # This special case is needed to support types defined under |
| 1150 | # from __future__ import annotations, where accessing the __annotations__ |
| 1151 | # attribute directly might return annotations for the wrong class. |
| 1152 | if isinstance(obj, type): |
| 1153 | try: |
| 1154 | ann = _BASE_GET_ANNOTATIONS(obj) |
| 1155 | except AttributeError: |
| 1156 | # For static types, the descriptor raises AttributeError. |
| 1157 | return None |
| 1158 | else: |
| 1159 | ann = getattr(obj, "__annotations__", None) |
| 1160 | if ann is None: |
| 1161 | return None |
| 1162 | |
| 1163 | if not isinstance(ann, dict): |
| 1164 | raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None") |
| 1165 | return ann |
no outgoing calls
no test coverage detected
searching dependent graphs…