Skip to content

Commit aaa451c

Browse files
chore: add type-hints to gitlab/v4/objects/milestones.py
1 parent ae3574c commit aaa451c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

gitlab/v4/objects/milestones.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, cast, TYPE_CHECKING, Union
22

33
from gitlab import cli
44
from gitlab import exceptions as exc
@@ -26,7 +26,7 @@ class GroupMilestone(SaveMixin, ObjectDeleteMixin, RESTObject):
2626

2727
@cli.register_custom_action("GroupMilestone")
2828
@exc.on_http_error(exc.GitlabListError)
29-
def issues(self, **kwargs):
29+
def issues(self, **kwargs: Any) -> RESTObjectList:
3030
"""List issues related to this milestone.
3131
3232
Args:
@@ -47,13 +47,15 @@ def issues(self, **kwargs):
4747

4848
path = f"{self.manager.path}/{self.get_id()}/issues"
4949
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
50+
if TYPE_CHECKING:
51+
assert isinstance(data_list, RESTObjectList)
5052
manager = GroupIssueManager(self.manager.gitlab, parent=self.manager._parent)
5153
# FIXME(gpocentek): the computed manager path is not correct
5254
return RESTObjectList(manager, GroupIssue, data_list)
5355

5456
@cli.register_custom_action("GroupMilestone")
5557
@exc.on_http_error(exc.GitlabListError)
56-
def merge_requests(self, **kwargs):
58+
def merge_requests(self, **kwargs: Any) -> RESTObjectList:
5759
"""List the merge requests related to this milestone.
5860
5961
Args:
@@ -73,6 +75,8 @@ def merge_requests(self, **kwargs):
7375
"""
7476
path = f"{self.manager.path}/{self.get_id()}/merge_requests"
7577
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
78+
if TYPE_CHECKING:
79+
assert isinstance(data_list, RESTObjectList)
7680
manager = GroupIssueManager(self.manager.gitlab, parent=self.manager._parent)
7781
# FIXME(gpocentek): the computed manager path is not correct
7882
return RESTObjectList(manager, GroupMergeRequest, data_list)
@@ -91,14 +95,19 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
9195
_list_filters = ("iids", "state", "search")
9296
_types = {"iids": types.ListAttribute}
9397

98+
def get(
99+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
100+
) -> GroupMilestone:
101+
return cast(GroupMilestone, super().get(id=id, lazy=lazy, **kwargs))
102+
94103

95104
class ProjectMilestone(PromoteMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
96105
_short_print_attr = "title"
97106
_update_uses_post = True
98107

99108
@cli.register_custom_action("ProjectMilestone")
100109
@exc.on_http_error(exc.GitlabListError)
101-
def issues(self, **kwargs):
110+
def issues(self, **kwargs: Any) -> RESTObjectList:
102111
"""List issues related to this milestone.
103112
104113
Args:
@@ -119,6 +128,8 @@ def issues(self, **kwargs):
119128

120129
path = f"{self.manager.path}/{self.get_id()}/issues"
121130
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
131+
if TYPE_CHECKING:
132+
assert isinstance(data_list, RESTObjectList)
122133
manager = ProjectIssueManager(self.manager.gitlab, parent=self.manager._parent)
123134
# FIXME(gpocentek): the computed manager path is not correct
124135
return RESTObjectList(manager, ProjectIssue, data_list)
@@ -145,6 +156,8 @@ def merge_requests(self, **kwargs: Any) -> RESTObjectList:
145156
"""
146157
path = f"{self.manager.path}/{self.get_id()}/merge_requests"
147158
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
159+
if TYPE_CHECKING:
160+
assert isinstance(data_list, RESTObjectList)
148161
manager = ProjectMergeRequestManager(
149162
self.manager.gitlab, parent=self.manager._parent
150163
)
@@ -165,3 +178,8 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
165178
)
166179
_list_filters = ("iids", "state", "search")
167180
_types = {"iids": types.ListAttribute}
181+
182+
def get(
183+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
184+
) -> ProjectMilestone:
185+
return cast(ProjectMilestone, super().get(id=id, lazy=lazy, **kwargs))

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ files = "."
1212
module = [
1313
"docs.*",
1414
"docs.ext.*",
15-
"gitlab.v4.objects.milestones",
1615
"gitlab.v4.objects.pipelines",
1716
"gitlab.v4.objects.repositories",
1817
"gitlab.v4.objects.services",

0 commit comments

Comments
 (0)