Skip to content

Commit

Permalink
Fix infinite range
Browse files Browse the repository at this point in the history
  • Loading branch information
Egsago-n committed Mar 25, 2024
1 parent f6ab93d commit 46116ce
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/phub/objects/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,24 @@ def __getitem__(self, index: int | slice) -> Iterator[QueryItem] | Iterator[Iter
return self.query._iter_page(items)

def wrap():
for i in range(index.start or 0,
index.stop or 0,
index.step or 1):

yield self[i]
try:
# Implementation of a slice range
i = index.start or 0
while not index.stop or i < index.stop:
yield self[i]
i += index.step or 1

except errors.NoResult:
return

return wrap()

def __iter__(self) -> Iterator[Iterator[QueryItem]]:
'''
Iterate each page.
'''

return self[:]

class Query:
'''
Expand Down

0 comments on commit 46116ce

Please sign in to comment.