Helper to generate an index specifying document. Takes a list of (key, direction) pairs.
(index_list: _IndexList)
| 173 | |
| 174 | |
| 175 | def _index_document(index_list: _IndexList) -> dict[str, Any]: |
| 176 | """Helper to generate an index specifying document. |
| 177 | |
| 178 | Takes a list of (key, direction) pairs. |
| 179 | """ |
| 180 | if not isinstance(index_list, (list, tuple, abc.Mapping)): |
| 181 | raise TypeError( |
| 182 | "must use a dictionary or a list of (key, direction) pairs, not: " + repr(index_list) |
| 183 | ) |
| 184 | if not len(index_list): |
| 185 | raise ValueError("key_or_list must not be empty") |
| 186 | |
| 187 | index: dict[str, Any] = {} |
| 188 | |
| 189 | if isinstance(index_list, abc.Mapping): |
| 190 | for key in index_list: |
| 191 | value = index_list[key] |
| 192 | _validate_index_key_pair(key, value) |
| 193 | index[key] = value |
| 194 | else: |
| 195 | for item in index_list: |
| 196 | if isinstance(item, str): |
| 197 | item = (item, ASCENDING) # noqa: PLW2901 |
| 198 | key, value = item |
| 199 | _validate_index_key_pair(key, value) |
| 200 | index[key] = value |
| 201 | return index |
| 202 | |
| 203 | |
| 204 | def _validate_index_key_pair(key: Any, value: Any) -> None: |
no test coverage detected