Skip to content

Commit 8cbf8a9

Browse files
Draft: ListMixin.list typing overload
Overload `ListMixin.list` method typing to return either `RESTObjectList` or `list` based on the passed options.
1 parent a6ac939 commit 8cbf8a9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

gitlab/mixins.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import enum
44
from collections.abc import Iterator
55
from types import ModuleType
6-
from typing import Any, Callable, Literal, overload, TYPE_CHECKING
6+
from typing import Any, Callable, Literal, NoReturn, overload, TYPE_CHECKING
7+
from warnings import deprecated
78

89
import requests
910

@@ -161,6 +162,34 @@ def refresh(self, **kwargs: Any) -> None:
161162
class ListMixin(HeadMixin[base.TObjCls]):
162163
_list_filters: tuple[str, ...] = ()
163164

165+
@overload
166+
@deprecated(
167+
"Calling a `list()` method without specifying `get_all=True` or "
168+
"`iterator=True` will miss certain items because of pagination."
169+
)
170+
def list(
171+
self,
172+
get_all: Literal[False] = False,
173+
iterator: Literal[False] = False,
174+
**kwargs: Any,
175+
) -> list[base.TObjCls]: ...
176+
177+
@overload
178+
def list(
179+
self,
180+
get_all: Literal[False] = False,
181+
iterator: Literal[True] = True,
182+
**kwargs: Any,
183+
) -> base.RESTObjectList: ...
184+
185+
@overload
186+
def list(
187+
self,
188+
get_all: Literal[True] = True,
189+
iterator: Literal[False] = False,
190+
**kwargs: Any,
191+
) -> list[base.TObjCls]: ...
192+
164193
@exc.on_http_error(exc.GitlabListError)
165194
def list(self, **kwargs: Any) -> base.RESTObjectList | list[base.TObjCls]:
166195
"""Retrieve a list of objects.

0 commit comments

Comments
 (0)