eqcorrscan / EQcorrscan

Earthquake detection and analysis in Python.
https://eqcorrscan.readthedocs.io/en/latest/
Other
166 stars 86 forks source link

Iterating through empty Party yields infinite loop #441

Closed calum-chamberlain closed 3 years ago

calum-chamberlain commented 3 years ago

Describe the bug Looping over an empty Party results in an infinite loop of None results

To Reproduce

from eqcorrscan import Party

party = Party()
for f in party:
    print(f)

Result:

None
None
...

for ever...

This happens because the Party.__getitem__ method returns None if the Party is empty.

Expected behavior To maintain the .__getitem__ behavior (which isn't correct, but is in the code in use now...) we can just define an __iter__ method and __next__ method properly as such:

def __iter__(self):
    return self.families.__iter__()

def __next__(self):
   return self.families.__next__()

Desktop (please complete the following information):

Additional context Bugger, what a silly mistake.

I should check the other objects to make sure iterating over them isn't similarly broken!