Skip to content

Commit 40adbd9

Browse files
committed
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)
1 parent edfde16 commit 40adbd9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

tweepy/cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def next(self):
9191
# to avoid requesting duplicate items.
9292
max_id = self.since_id - 1 if self.max_id else None
9393
data = self.method(max_id = max_id, *self.args, **self.kargs)
94+
if len(data) == 0:
95+
raise StopIteration
9496
self.max_id = data.max_id
9597
self.since_id = data.since_id
9698
return data
@@ -99,6 +101,8 @@ def prev(self):
99101
"""Fetch a set of items with IDs greater than current set."""
100102
since_id = self.max_id
101103
data = self.method(since_id = since_id, *self.args, **self.kargs)
104+
if len(data) == 0:
105+
raise StopIteration
102106
self.max_id = data.max_id
103107
self.since_id = data.since_id
104108
return data

tweepy/models.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ def __init__(self, max_id=None, since_id=None):
1616

1717
@property
1818
def max_id(self):
19-
return self._max_id or max(self.ids())
19+
if self._max_id:
20+
return self._max_id
21+
ids = self.ids()
22+
return max(ids) if ids else None
2023

2124
@property
2225
def since_id(self):
23-
return self._since_id or min(self.ids())
26+
if self._since_id:
27+
return self._since_id
28+
ids = self.ids()
29+
return min(ids) if ids else None
2430

2531
def ids(self):
2632
return [item.id for item in self if hasattr(item, 'id')]

0 commit comments

Comments
 (0)