diff --git a/pywa/client.py b/pywa/client.py index a2523b2..4dc74ce 100644 --- a/pywa/client.py +++ b/pywa/client.py @@ -1488,6 +1488,7 @@ def unblock_users( def get_blocked_users( self, phone_id: str | int | None = None, + *, limit: int | None = None, batch_size: int | None = None, ) -> Result[User]: @@ -1502,10 +1503,10 @@ def get_blocked_users( Args: phone_id: The phone ID to get the list of blocked users from (optional, if not provided, the client's phone ID will be used). limit: The maximum number of users to return (optional, if not provided, all users will be returned). - batch_size: The number of users to return per request (optional, default: 50). + batch_size: The number of users to return per request (optional). Returns: - A list of blocked users. + A Result object with the list of blocked users. You can iterate over the result to get the users. """ return Result( fetcher=functools.partial( @@ -2394,7 +2395,7 @@ def get_flows( batch_size: The number of flows to return in each batch (optional). Returns: - The details of all flows. + A Result object with the list of flows. You can iterate over the result to get the flows. """ return Result( fetcher=functools.partial( diff --git a/pywa/types/others.py b/pywa/types/others.py index 52105fd..a2110ea 100644 --- a/pywa/types/others.py +++ b/pywa/types/others.py @@ -1009,6 +1009,7 @@ def __init__( self._all_items: list[_T] = [] self._after = None self._has_next = True + self._iterating = False def _process_data(self, data: dict) -> list[_T]: self._after = data.get("paging", {}).get("cursors", {}).get("after") @@ -1026,11 +1027,13 @@ async def _get_items_async(self) -> list[_T]: def __iter__(self) -> Result[_T]: if self._is_async: raise TypeError("Use `async for` for async results.") + self._iterating = True return self def __aiter__(self) -> Result[_T]: if not self._is_async: raise TypeError("Use `for` for sync results.") + self._iterating = True return self def _is_fetch_next_needed(self) -> bool: @@ -1061,10 +1064,16 @@ async def __anext__(self) -> _T: return item def __bool__(self) -> bool: + if not self._iterating: + raise TypeError("Result is not being iterated over.") return self._has_next or bool(self._all_items) def __repr__(self) -> str: - return f"Result({self._all_items!r}, has_next={self._has_next})" + return ( + f"Result({self._all_items!r}, has_next={self._has_next})" + if self._iterating + else "Result()" + ) def __str__(self) -> str: return self.__repr__() diff --git a/pywa_async/client.py b/pywa_async/client.py index 4762fff..a2b6e3d 100644 --- a/pywa_async/client.py +++ b/pywa_async/client.py @@ -1252,6 +1252,7 @@ async def unblock_users( async def get_blocked_users( self, phone_id: str | int | None = None, + *, limit: int | None = None, batch_size: int | None = None, ) -> Result[User]: @@ -1267,10 +1268,10 @@ async def get_blocked_users( Args: phone_id: The phone ID to get the list of blocked users from (optional, if not provided, the client's phone ID will be used). limit: The maximum number of users to return (optional, if not provided, all users will be returned). - batch_size: The number of users to return per request (optional, default: 50). + batch_size: The number of users to return per request (optional). Returns: - A list of blocked users. + A Result object with the list of blocked users. You can iterate over the result to get the users. """ return Result( fetcher=functools.partial( @@ -2180,7 +2181,7 @@ async def get_flows( batch_size: The number of flows to return in each batch (optional). Returns: - The details of all flows. + A Result object with the list of flows. You can iterate over the result to get the flows. """ return Result( fetcher=functools.partial(