Skip to content

Commit b6f3fe4

Browse files
more minor adjustments to response types
1 parent 099a52f commit b6f3fe4

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

elasticsearch_dsl/response/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@
4040
from ..search_base import Request, SearchBase
4141
from ..update_by_query_base import UpdateByQueryBase
4242

43-
__all__ = ["Response", "AggResponse", "UpdateByQueryResponse", "Hit", "HitMeta"]
43+
__all__ = [
44+
"Response",
45+
"AggResponse",
46+
"UpdateByQueryResponse",
47+
"Hit",
48+
"HitMeta",
49+
"AggregateResponseType",
50+
]
4451

4552

4653
class Response(AttrDict[Any], Generic[_R]):

examples/async/composite_agg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
import asyncio
1919
import os
20-
from typing import Any, AsyncIterator, Dict, Mapping, Sequence
20+
from typing import Any, AsyncIterator, Dict, Mapping, Sequence, cast
2121

2222
from elasticsearch.helpers import async_bulk
2323

2424
from elasticsearch_dsl import Agg, AsyncSearch, Response, aggs, async_connections
25+
from elasticsearch_dsl.types import CompositeAggregate
2526
from tests.test_integration.test_data import DATA, GIT_INDEX
2627

2728

@@ -30,7 +31,7 @@ async def scan_aggs(
3031
source_aggs: Sequence[Mapping[str, Agg]],
3132
inner_aggs: Dict[str, Agg] = {},
3233
size: int = 10,
33-
) -> AsyncIterator[Any]:
34+
) -> AsyncIterator[CompositeAggregate]:
3435
"""
3536
Helper function used to iterate over all possible bucket combinations of
3637
``source_aggs``, returning results of ``inner_aggs`` for each. Uses the
@@ -54,7 +55,7 @@ async def run_search(**kwargs: Any) -> Response:
5455
response = await run_search()
5556
while response.aggregations["comp"].buckets:
5657
for b in response.aggregations["comp"].buckets:
57-
yield b
58+
yield cast(CompositeAggregate, b)
5859
if "after_key" in response.aggregations["comp"]:
5960
after = response.aggregations["comp"].after_key
6061
else:

examples/async/parent_child.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
from elasticsearch_dsl import (
4848
AsyncDocument,
49-
AsyncIndex,
5049
AsyncSearch,
5150
Date,
5251
InnerDoc,
@@ -92,7 +91,7 @@ class Post(AsyncDocument):
9291
# definitions here help type checkers understand additional arguments
9392
# that are allowed in the constructor
9493
_routing: str = mapped_field(default=None)
95-
_index: AsyncIndex = mapped_field(default=None)
94+
_index: str = mapped_field(default=None)
9695
_id: Optional[int] = mapped_field(default=None)
9796

9897
created: Optional[datetime] = mapped_field(default=None)

examples/composite_agg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
# under the License.
1717

1818
import os
19-
from typing import Any, Dict, Iterator, Mapping, Sequence
19+
from typing import Any, Dict, Iterator, Mapping, Sequence, cast
2020

2121
from elasticsearch.helpers import bulk
2222

2323
from elasticsearch_dsl import Agg, Response, Search, aggs, connections
24+
from elasticsearch_dsl.types import CompositeAggregate
2425
from tests.test_integration.test_data import DATA, GIT_INDEX
2526

2627

@@ -29,7 +30,7 @@ def scan_aggs(
2930
source_aggs: Sequence[Mapping[str, Agg]],
3031
inner_aggs: Dict[str, Agg] = {},
3132
size: int = 10,
32-
) -> Iterator[Any]:
33+
) -> Iterator[CompositeAggregate]:
3334
"""
3435
Helper function used to iterate over all possible bucket combinations of
3536
``source_aggs``, returning results of ``inner_aggs`` for each. Uses the
@@ -53,7 +54,7 @@ def run_search(**kwargs: Any) -> Response:
5354
response = run_search()
5455
while response.aggregations["comp"].buckets:
5556
for b in response.aggregations["comp"].buckets:
56-
yield b
57+
yield cast(CompositeAggregate, b)
5758
if "after_key" in response.aggregations["comp"]:
5859
after = response.aggregations["comp"].after_key
5960
else:

examples/parent_child.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from elasticsearch_dsl import (
4747
Date,
4848
Document,
49-
Index,
5049
InnerDoc,
5150
Join,
5251
Keyword,
@@ -91,7 +90,7 @@ class Post(Document):
9190
# definitions here help type checkers understand additional arguments
9291
# that are allowed in the constructor
9392
_routing: str = mapped_field(default=None)
94-
_index: Index = mapped_field(default=None)
93+
_index: str = mapped_field(default=None)
9594
_id: Optional[int] = mapped_field(default=None)
9695

9796
created: Optional[datetime] = mapped_field(default=None)

utils/templates/response.__init__.py.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if TYPE_CHECKING:
4040
from ..update_by_query_base import UpdateByQueryBase
4141
from .. import types
4242

43-
__all__ = ["Response", "AggResponse", "UpdateByQueryResponse", "Hit", "HitMeta"]
43+
__all__ = ["Response", "AggResponse", "UpdateByQueryResponse", "Hit", "HitMeta", "AggregateResponseType"]
4444

4545

4646
class Response(AttrDict[Any], Generic[_R]):

0 commit comments

Comments
 (0)