Don't make an unnecessary API call in PageIterator
authorAaron Hill <aa1ronham@gmail.com>
Sun, 13 Apr 2014 19:45:38 +0000 (15:45 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sun, 13 Apr 2014 19:45:38 +0000 (15:45 -0400)
tweepy/cursor.py

index ef81c524403c0f8c3028b2398312c3eda2dc2311..451e849c59f404277d6d7bb6c9e140b00a366b1b 100644 (file)
@@ -133,10 +133,13 @@ class PageIterator(BaseIterator):
         self.current_page = 0
 
     def next(self):
-        self.current_page += 1
+        if self.limit > 0 and self.current_page > self.limit:
+            raise StopIteration
+
         items = self.method(page=self.current_page, *self.args, **self.kargs)
-        if len(items) == 0 or (self.limit > 0 and self.current_page > self.limit):
+        if len(items) == 0:
             raise StopIteration
+        self.current_page += 1
         return items
 
     def prev(self):