Use next built-in function in place of next method for iterators
authorHarmon <Harmon758@gmail.com>
Sat, 26 Dec 2020 09:18:46 +0000 (03:18 -0600)
committerHarmon <Harmon758@gmail.com>
Sat, 26 Dec 2020 09:18:46 +0000 (03:18 -0600)
docs/code_snippet.rst
tests/test_cursors.py
tweepy/cursor.py

index f838e2a89ce59057bb80b5881c535b3ddee5de93..2674693c223c4e92ac788bd82271deb370b89959 100644 (file)
@@ -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)
    
index 3f461574375fcbc2254996b6a6787c0a3a3db51a..65923562dac798cb4abd064a0ae580487630888c 100644 (file)
@@ -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')
index 85eabce664eba8a56583b326ac147762e214661e..d045a35560818a12c34652fc6fc46378f4958a0d 100644 (file)
@@ -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