Coverage for src/fastoai/pagination.py: 89%

1 from typing import Generic, Literal, TypeVar, cast

2

3 from openai.pagination import AsyncCursorPage, CursorPageItem

4 from pydantic import computed_field

5

6 _T = TypeVar("_T")

7

8

9 class AsyncCursorPage(AsyncCursorPage[_T], Generic[_T]):

10 object: Literal["list"] = "list"

11

12 @computed_field

13 def has_more(self) -> bool:

14 return self.has_next_page()

15

16 @computed_field

17 def first_id(self) -> str | None:

18 if not self.data:

19 return None

20 return cast(CursorPageItem, self.data[0]).id

21

22 @computed_field

23 def last_id(self) -> str | None:

24 if not self.data:

25 return None

26 return cast(CursorPageItem, self.data[-1]).id