Stone-Soup
Stone-Soup copied to clipboard
When `iter` is called on an iterator (Tracker), it shouldn't reset according to Python standard
This issue rarely is a problem, but it is when using heapq. (See example below)
from stonesoup.tracker import Tracker
import heapq
class MyTracker(Tracker):
a_list = [0, 1, 2, 3, 4, 5]
def __iter__(self):
self.list_iter = iter(self.a_list)
return super().__iter__()
def __next__(self):
return next(self.list_iter) ** 2
def tracks(self):
return self.a_list
print(list(MyTracker()))
print(list(heapq.merge(MyTracker(), MyTracker())))
Expected output:
[0, 1, 4, 9, 16, 25]
[0, 0, 1, 1, 4, 4, 9, 9, 16, 16, 25, 25]
Actual output:
[0, 1, 4, 9, 16, 25]
[0, 0, 1, 1, 4, 4, 9, 9, 16, 16, 25, 25, 0, 1, 4, 9, 16, 25]