def hint_or_sort_cursor(
cursor: Cursor,
/,
indexes: typing.Union[str, typing.Sequence[typing.Tuple[str, int]]],
) -> Cursor:
index_info = cursor.collection.index_information()
if isinstance(indexes, str):
if indexes not in index_info:
return cursor.sort(indexes)
else:
for index in indexes:
if isinstance(index, tuple):
index_name, _ = index
if index_name not in index_info:
return cursor.sort(indexes)
if isinstance(index, str):
if index not in index_info:
return cursor.sort(indexes)
return cursor.hint(indexes)