From 67847f33834d08e8af2fe08166d784795977465d Mon Sep 17 00:00:00 2001 From: Peng Cheng Date: Wed, 11 Nov 2026 15:20:36 +0800 Subject: [PATCH] Fix index listing pagination types --- .github/workflows/tests.yml | 2 +- meilisearch/client.py | 24 +++++++++++++++++++----- tests/types/index_pagination.py | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 tests/types/index_pagination.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 814b80f2..248027d9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -73,7 +73,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: mypy type check - run: uv run mypy meilisearch + run: uv run mypy meilisearch tests/types ruff: name: ruff diff --git a/meilisearch/client.py b/meilisearch/client.py index 8003f006..4639170b 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -7,7 +7,7 @@ import json import re from collections.abc import Iterator, Mapping, MutableMapping, Sequence -from typing import Any +from typing import Any, TypedDict from urllib import parse from meilisearch._httprequests import HttpRequests @@ -25,6 +25,20 @@ from meilisearch.task import TaskHandler +class _IndexPagination(TypedDict): + limit: int + offset: int + total: int + + +class IndexesResults(_IndexPagination): + results: list[Index] + + +class RawIndexesResults(_IndexPagination): + results: list[dict[str, Any]] + + class Client: """ A client for the Meilisearch API @@ -129,7 +143,7 @@ def delete_index(self, uid: str, *, metadata: str | None = None) -> TaskInfo: return TaskInfo(**task) - def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str, list[Index]]: + def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> IndexesResults: """Get all indexes. Parameters @@ -140,7 +154,7 @@ def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str, Returns ------- indexes: - Dictionary with limit, offset, total and results a list of Index instances. + Dictionary with limit, offset, total and a list of Index instances in results. Raises ------ @@ -163,7 +177,7 @@ def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str, ] return response - def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> list[dict[str, Any]]: + def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> RawIndexesResults: """Get all indexes in dictionary format. Parameters @@ -174,7 +188,7 @@ def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> list[d Returns ------- indexes: - Dictionary with limit, offset, total and results a list of indexes in dictionary format. (e.g [{ 'uid': 'movies' 'primaryKey': 'objectID' }]) + Dictionary with limit, offset, total and a list of raw index dictionaries in results. Raises ------ diff --git a/tests/types/index_pagination.py b/tests/types/index_pagination.py new file mode 100644 index 00000000..56b74e12 --- /dev/null +++ b/tests/types/index_pagination.py @@ -0,0 +1,20 @@ +from typing import Any + +from typing_extensions import assert_type + +from meilisearch import Client +from meilisearch.index import Index + + +def check_index_pagination(client: Client) -> None: + indexes = client.get_indexes() + assert_type(indexes["results"], list[Index]) + assert_type(indexes["limit"], int) + assert_type(indexes["offset"], int) + assert_type(indexes["total"], int) + + raw = client.get_raw_indexes() + assert_type(raw["results"], list[dict[str, Any]]) + assert_type(raw["limit"], int) + assert_type(raw["offset"], int) + assert_type(raw["total"], int)