Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When iter is called on an iterator (Tracker), it shouldn't reset according to Python standard #883

Open
gawebb-dstl opened this issue Nov 2, 2023 · 0 comments
Assignees

Comments

@gawebb-dstl
Copy link
Contributor

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]

@gawebb-dstl gawebb-dstl self-assigned this Nov 2, 2023
@gawebb-dstl gawebb-dstl changed the title When iter is called on Tracker, it shouldn't reset according to Python standard When iter is called on an iterator (Tracker), it shouldn't reset according to Python standard Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant