From e82565315330883823bd5191069253a941cb2683 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Sat, 5 Feb 2022 12:01:42 -0800 Subject: [PATCH] chore: correct type-hints for per_page attrbute There are occasions where a GitLab `list()` call does not return the `x-per-page` header. For example the listing of custom attributes. Update the type-hints to reflect that. --- gitlab/base.py | 2 +- gitlab/client.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/gitlab/base.py b/gitlab/base.py index aa18dcfd7..7f685425a 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -302,7 +302,7 @@ def next_page(self) -> Optional[int]: return self._list.next_page @property - def per_page(self) -> int: + def per_page(self) -> Optional[int]: """The number of items per page.""" return self._list.per_page diff --git a/gitlab/client.py b/gitlab/client.py index a4c58313a..9d1eebdd9 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -1039,11 +1039,9 @@ def next_page(self) -> Optional[int]: return int(self._next_page) if self._next_page else None @property - def per_page(self) -> int: + def per_page(self) -> Optional[int]: """The number of items per page.""" - if TYPE_CHECKING: - assert self._per_page is not None - return int(self._per_page) + return int(self._per_page) if self._per_page is not None else None # NOTE(jlvillal): When a query returns more than 10,000 items, GitLab doesn't return # the headers 'x-total-pages' and 'x-total'. In those cases we return None.