From: Joshua Roesslein Date: Mon, 10 Jun 2013 05:35:06 +0000 (-0700) Subject: Fix a few bugs with the new ID cursors. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=40adbd9d5ca3f1cdd9e45ba4a3fcae92f1f6d6cd;p=tweepy.git Fix a few bugs with the new ID cursors. - stop once end of collection reached (empty result). - don't raise ValueError if ResultSet is empty when trying to get max/min ID of the set (max() and min() don't accept empty lists) --- diff --git a/tweepy/cursor.py b/tweepy/cursor.py index 680b9e8..edda0ba 100644 --- a/tweepy/cursor.py +++ b/tweepy/cursor.py @@ -91,6 +91,8 @@ class IdIterator(BaseIterator): # to avoid requesting duplicate items. max_id = self.since_id - 1 if self.max_id else None data = self.method(max_id = max_id, *self.args, **self.kargs) + if len(data) == 0: + raise StopIteration self.max_id = data.max_id self.since_id = data.since_id return data @@ -99,6 +101,8 @@ class IdIterator(BaseIterator): """Fetch a set of items with IDs greater than current set.""" since_id = self.max_id data = self.method(since_id = since_id, *self.args, **self.kargs) + if len(data) == 0: + raise StopIteration self.max_id = data.max_id self.since_id = data.since_id return data diff --git a/tweepy/models.py b/tweepy/models.py index 7171c40..fcccbf1 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -16,11 +16,17 @@ class ResultSet(list): @property def max_id(self): - return self._max_id or max(self.ids()) + if self._max_id: + return self._max_id + ids = self.ids() + return max(ids) if ids else None @property def since_id(self): - return self._since_id or min(self.ids()) + if self._since_id: + return self._since_id + ids = self.ids() + return min(ids) if ids else None def ids(self): return [item.id for item in self if hasattr(item, 'id')]