|
26 | 26 | Optional, |
27 | 27 | Sequence, |
28 | 28 | Tuple, |
29 | | - TypedDict, |
30 | 29 | Union, |
31 | 30 | cast, |
32 | 31 | ) |
@@ -196,7 +195,7 @@ def search_after(self) -> "SearchBase[_R]": |
196 | 195 | return self._search.extra(search_after=self.hits[-1].meta.sort) # type: ignore |
197 | 196 |
|
198 | 197 |
|
199 | | -_Aggregate = Union[ |
| 198 | +AggregateResponseType = Union[ |
200 | 199 | "types.CardinalityAggregate", |
201 | 200 | "types.HdrPercentilesAggregate", |
202 | 201 | "types.HdrPercentileRanksAggregate", |
@@ -268,28 +267,28 @@ def search_after(self) -> "SearchBase[_R]": |
268 | 267 | "types.MatrixStatsAggregate", |
269 | 268 | "types.GeoLineAggregate", |
270 | 269 | ] |
271 | | -_AggResponseMeta = TypedDict( |
272 | | - "_AggResponseMeta", {"search": "Request[_R]", "aggs": Mapping[str, _Aggregate]} |
273 | | -) |
274 | 270 |
|
275 | 271 |
|
276 | 272 | class AggResponse(AttrDict[Any], Generic[_R]): |
| 273 | + """An Elasticsearch aggregation response.""" |
| 274 | + |
277 | 275 | _meta: Dict[str, Any] |
278 | 276 |
|
279 | 277 | def __init__(self, aggs: "Agg[_R]", search: "Request[_R]", data: Dict[str, Any]): |
280 | 278 | super(AttrDict, self).__setattr__("_meta", {"search": search, "aggs": aggs}) |
281 | 279 | super().__init__(data) |
282 | 280 |
|
283 | | - def __getitem__(self, attr_name: str) -> _Aggregate: |
| 281 | + def __getitem__(self, attr_name: str) -> AggregateResponseType: |
284 | 282 | if attr_name in self._meta["aggs"]: |
285 | 283 | # don't do self._meta['aggs'][attr_name] to avoid copying |
286 | 284 | agg = self._meta["aggs"].aggs[attr_name] |
287 | 285 | return cast( |
288 | | - _Aggregate, agg.result(self._meta["search"], self._d_[attr_name]) |
| 286 | + AggregateResponseType, |
| 287 | + agg.result(self._meta["search"], self._d_[attr_name]), |
289 | 288 | ) |
290 | 289 | return super().__getitem__(attr_name) # type: ignore |
291 | 290 |
|
292 | | - def __iter__(self) -> Iterator[_Aggregate]: # type: ignore[override] |
| 291 | + def __iter__(self) -> Iterator[AggregateResponseType]: # type: ignore[override] |
293 | 292 | for name in self._meta["aggs"]: |
294 | 293 | yield self[name] |
295 | 294 |
|
|
0 commit comments