Skip to content
Snippets Groups Projects
Commit 674ff19a authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix iterators

parent fb0c80d1
No related branches found
No related tags found
No related merge requests found
...@@ -14,3 +14,8 @@ Then you can create and retrieve particular series: ...@@ -14,3 +14,8 @@ Then you can create and retrieve particular series:
.. autoclass:: tempsdb.series.TimeSeries .. autoclass:: tempsdb.series.TimeSeries
:members: :members:
You retrieve their data via Iterators:
.. autoclass:: tempsdb.iterators.Iterator
:members:
...@@ -72,24 +72,28 @@ cdef class Iterator: ...@@ -72,24 +72,28 @@ cdef class Iterator:
return 0 return 0
def __next__(self) -> tp.Tuple[int, bytes]: def __next__(self) -> tp.Tuple[int, bytes]:
return self.next() cdef tuple tpl = self.next()
if tpl is None:
raise StopIteration()
return tpl
cpdef tuple next(self): cpdef tuple next(self):
""" """
Return next element Return next element or None, if list was exhausted
:return: next element :return: next element
:rtype: tp.Tuple[int, bytes] :rtype: tp.Optional[tp.Tuple[int, bytes]]
""" """
if self.current_chunk is None:
self.get_next()
if self.i == self.limit:
self.get_next()
try: try:
if self.current_chunk is None:
self.get_next()
if self.i == self.limit:
self.get_next()
return self.current_chunk.get_piece_at(self.i) return self.current_chunk.get_piece_at(self.i)
except StopIteration:
return None
finally: finally:
self.i += 1 self.i += 1
def __iter__(self) -> Iterator: def __iter__(self) -> Iterator:
return self return self
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment