- 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)
# 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
"""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
@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')]