Skip to content

Commit

Permalink
Update query.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oribarilan committed Jan 22, 2024
1 parent ff54a92 commit c87a931
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fliq/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,15 @@ def at(self,
ElementNotFoundException: In case the query is too short.
QueryIsUnexpectedlyEmptyException: In case the query is empty.
"""
# if items can be accessed using index, do that
if isinstance(self._items, collections.abc.Sequence):
try:
return self._items[index] # type: ignore # (item is of type T)
except IndexError:
if default is MISSING:
raise ElementNotFoundException()
else:
return default # type: ignore # default is not MISSING
try:
return self.skip(index).first(default=default)
except QueryIsUnexpectedlyEmptyException:
Expand Down

0 comments on commit c87a931

Please sign in to comment.