From c1861efa680e3a1d8e5d720db3e5833a402867c7 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sat, 26 Dec 2020 03:18:46 -0600 Subject: [PATCH] Use next built-in function in place of next method for iterators --- docs/code_snippet.rst | 4 ++-- tests/test_cursors.py | 4 ++-- tweepy/cursor.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/code_snippet.rst b/docs/code_snippet.rst index f838e2a..2674693 100644 --- a/docs/code_snippet.rst +++ b/docs/code_snippet.rst @@ -55,7 +55,7 @@ This snippet will follow every follower of the authenticated user. Handling the rate limit using cursors ===================================== -Since cursors raise ``RateLimitError``\ s in their ``next()`` method, +Since cursors raise ``RateLimitError``\ s while iterating, handling them can be done by wrapping the cursor in an iterator. Running this snippet will print all users you follow that themselves follow @@ -70,7 +70,7 @@ will wait for 15 minutes each time it hits the rate limit. def limit_handled(cursor): while True: try: - yield cursor.next() + yield next(cursor) except tweepy.RateLimitError: time.sleep(15 * 60) diff --git a/tests/test_cursors.py b/tests/test_cursors.py index 3f46157..6592356 100644 --- a/tests/test_cursors.py +++ b/tests/test_cursors.py @@ -38,10 +38,10 @@ class TweepyCursorTests(TweepyTestCase): @tape.use_cassette('testcursornext.json') def testcursornext(self): """ - Test cursor.next() behavior, id being passed correctly. + Test next(cursor) behavior, id being passed correctly. Regression test for issue #518 """ cursor = Cursor(self.api.user_timeline, id='Twitter').items(5) - status = cursor.next() + status = next(cursor) self.assertEqual(status.user.screen_name, 'Twitter') diff --git a/tweepy/cursor.py b/tweepy/cursor.py index 85eabce..d045a35 100644 --- a/tweepy/cursor.py +++ b/tweepy/cursor.py @@ -240,9 +240,9 @@ class ItemIterator(BaseIterator): raise StopIteration if self.current_page is None or self.page_index == len(self.current_page) - 1: # Reached end of current page, get the next page... - self.current_page = self.page_iterator.next() + self.current_page = next(self.page_iterator) while len(self.current_page) == 0: - self.current_page = self.page_iterator.next() + self.current_page = next(self.page_iterator) self.page_index = -1 self.page_index += 1 self.num_tweets += 1 -- 2.25.1