From 1a54c15a71d054c6421e29cbcefcb9f2186cad49 Mon Sep 17 00:00:00 2001 From: Erik Zscheile Date: Tue, 26 Jan 2021 22:19:13 +0100 Subject: [PATCH 1/2] PEP 479: Change StopIteration handling inside generators --- twython/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twython/api.py b/twython/api.py index bb10db0a..bd49c49c 100644 --- a/twython/api.py +++ b/twython/api.py @@ -501,7 +501,7 @@ def cursor(self, function, return_pages=False, **params): content = function(**params) if not content: - raise StopIteration + return if hasattr(function, 'iter_key'): results = content.get(function.iter_key) @@ -516,7 +516,7 @@ def cursor(self, function, return_pages=False, **params): if function.iter_mode == 'cursor' and \ content['next_cursor_str'] == '0': - raise StopIteration + return try: if function.iter_mode == 'id': @@ -529,7 +529,7 @@ def cursor(self, function, return_pages=False, **params): params = dict(parse_qsl(next_results.query)) else: # No more results - raise StopIteration + return else: # Twitter gives tweets in reverse chronological order: params['max_id'] = str(int(content[-1]['id_str']) - 1) From 61c1ba9600986d8263af81b8cee954828bb7ce7c Mon Sep 17 00:00:00 2001 From: Erik Zscheile Date: Tue, 26 Jan 2021 22:22:56 +0100 Subject: [PATCH 2/2] PEP 479: add appropriate __future__ tag --- twython/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/twython/api.py b/twython/api.py index bd49c49c..5de6c67c 100644 --- a/twython/api.py +++ b/twython/api.py @@ -9,6 +9,7 @@ dealing with the Twitter API """ +from __future__ import generator_stop import warnings import re