Skip to content

Commit 12b99ea

Browse files
type hints for remaining elasticsearch_dsl classes (#1853) (#1855)
* use a single _R typevar * type hints for remainig elasticsearch_dsl classes * feedback (cherry picked from commit 2c2d0f3) Co-authored-by: Miguel Grinberg <[email protected]>
1 parent 2ee02ee commit 12b99ea

30 files changed

+547
-413
lines changed

elasticsearch_dsl/_async/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class AsyncDocument(DocumentBase, metaclass=AsyncIndexMeta):
8484

8585
@classmethod
8686
def _get_using(cls, using: Optional[AsyncUsingType] = None) -> AsyncUsingType:
87-
return using or cls._index._using
87+
return cast(AsyncUsingType, using or cls._index._using)
8888

8989
@classmethod
9090
def _get_connection(

elasticsearch_dsl/_async/faceted_search.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import TYPE_CHECKING
19+
1820
from elasticsearch_dsl.faceted_search_base import FacetedResponse, FacetedSearchBase
1921

22+
from ..utils import _R
2023
from .search import AsyncSearch
2124

25+
if TYPE_CHECKING:
26+
from ..response import Response
27+
28+
29+
class AsyncFacetedSearch(FacetedSearchBase[_R]):
30+
_s: AsyncSearch[_R]
31+
32+
async def count(self) -> int:
33+
return await self._s.count()
2234

23-
class AsyncFacetedSearch(FacetedSearchBase):
24-
def search(self):
35+
def search(self) -> AsyncSearch[_R]:
2536
"""
2637
Returns the base Search object to which the facets are added.
2738
2839
You can customize the query by overriding this method and returning a
2940
modified search object.
3041
"""
31-
s = AsyncSearch(doc_type=self.doc_types, index=self.index, using=self.using)
42+
s = AsyncSearch[_R](doc_type=self.doc_types, index=self.index, using=self.using)
3243
return s.response_class(FacetedResponse)
3344

34-
async def execute(self):
45+
async def execute(self) -> "Response[_R]":
3546
"""
3647
Execute the search and return the response.
3748
"""

0 commit comments

Comments
 (0)