async for response in AsyncPaginationIterator(
self.method, *self.args, **self.kwargs
):
- if response.data is not None:
- for data in response.data:
- yield data
- count += 1
- if count == limit:
- return
+ if isinstance(response, Response):
+ response_data = response.data or []
+ elif isinstance(response, dict):
+ response_data = response.get("data", [])
+ else:
+ raise RuntimeError(
+ "AsyncPaginator.flatten does not support the "
+ f"{type(response)} return type for "
+ f"{self.method.__qualname__}"
+ )
+ for data in response_data:
+ yield data
+ count += 1
+ if count == limit:
+ return
class AsyncPaginationIterator:
return
count = 0
- for response in PaginationIterator(self.method, *self.args,
- **self.kwargs):
- if response.data is not None:
- for data in response.data:
- yield data
- count += 1
- if count == limit:
- return
+ for response in PaginationIterator(
+ self.method, *self.args, **self.kwargs
+ ):
+ if isinstance(response, Response):
+ response_data = response.data or []
+ elif isinstance(response, dict):
+ response_data = response.get("data", [])
+ else:
+ raise RuntimeError(
+ f"Paginator.flatten does not support the {type(response)} "
+ f"return type for {self.method.__qualname__}"
+ )
+ for data in response_data:
+ yield data
+ count += 1
+ if count == limit:
+ return
class PaginationIterator: