From cf5b75566d794395c690ad591c0507f475c6e21a Mon Sep 17 00:00:00 2001 From: fourjr <28086837+fourjr@users.noreply.github.com> Date: Thu, 15 Nov 2018 20:43:10 +0800 Subject: [PATCH] Improved error handling for iter and aiter for paginatedattrdict --- CHANGELOG.md | 4 +++- clashroyale/official_api/models.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48f7323..3e982a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] -No changes yet + +### Added +- RuntimeError if you were calling the wrong method (iter/aiter) on an inappropriate client (i.e. async client -> iter/blocking client -> aiter) ## [4.0.0] - 11/11/2018 ### Added diff --git a/clashroyale/official_api/models.py b/clashroyale/official_api/models.py index 8771abe..3cc76d5 100644 --- a/clashroyale/official_api/models.py +++ b/clashroyale/official_api/models.py @@ -160,6 +160,8 @@ def __getitem__(self, item): @async_generator async def __aiter__(self): + if not self.client.is_async: + raise RuntimeError('Calling __aiter__ on an asynchronus client. Use :for: not :async for:') while True: index = 0 for _ in range(index, len(self.raw_data)): @@ -169,6 +171,8 @@ async def __aiter__(self): break def __iter__(self): + if self.client.is_async: + raise RuntimeError('Calling __iter__ on an asynchronus client. Use :async for: not :for:') while True: index = 0 for _ in range(index, len(self.raw_data)):