Skip to content

Commit 0951989

Browse files
authored
Merge pull request #1681 from python-gitlab/jlvillal/mypy_ensure_type_hints
Ensure get() methods have correct type-hints
2 parents a553ee7 + 46773a8 commit 0951989

25 files changed

+437
-6
lines changed

gitlab/v4/objects/audit_events.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
GitLab API:
33
https://docs.gitlab.com/ee/api/audit_events.html
44
"""
5+
from typing import Any, cast, Union
6+
57
from gitlab.base import RESTManager, RESTObject
68
from gitlab.mixins import RetrieveMixin
79

@@ -26,6 +28,9 @@ class AuditEventManager(RetrieveMixin, RESTManager):
2628
_obj_cls = AuditEvent
2729
_list_filters = ("created_after", "created_before", "entity_type", "entity_id")
2830

31+
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> AuditEvent:
32+
return cast(AuditEvent, super().get(id=id, lazy=lazy, **kwargs))
33+
2934

3035
class GroupAuditEvent(RESTObject):
3136
_id_attr = "id"
@@ -37,6 +42,11 @@ class GroupAuditEventManager(RetrieveMixin, RESTManager):
3742
_from_parent_attrs = {"group_id": "id"}
3843
_list_filters = ("created_after", "created_before")
3944

45+
def get(
46+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
47+
) -> GroupAuditEvent:
48+
return cast(GroupAuditEvent, super().get(id=id, lazy=lazy, **kwargs))
49+
4050

4151
class ProjectAuditEvent(RESTObject):
4252
_id_attr = "id"
@@ -48,6 +58,11 @@ class ProjectAuditEventManager(RetrieveMixin, RESTManager):
4858
_from_parent_attrs = {"project_id": "id"}
4959
_list_filters = ("created_after", "created_before")
5060

61+
def get(
62+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
63+
) -> ProjectAuditEvent:
64+
return cast(ProjectAuditEvent, super().get(id=id, lazy=lazy, **kwargs))
65+
5166

5267
class ProjectAudit(ProjectAuditEvent):
5368
pass

gitlab/v4/objects/award_emojis.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
35

@@ -27,6 +29,11 @@ class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager):
2729
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
2830
_create_attrs = RequiredOptional(required=("name",))
2931

32+
def get(
33+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
34+
) -> ProjectIssueAwardEmoji:
35+
return cast(ProjectIssueAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
36+
3037

3138
class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
3239
pass
@@ -42,6 +49,11 @@ class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
4249
}
4350
_create_attrs = RequiredOptional(required=("name",))
4451

52+
def get(
53+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
54+
) -> ProjectIssueNoteAwardEmoji:
55+
return cast(ProjectIssueNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
56+
4557

4658
class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject):
4759
pass
@@ -53,6 +65,13 @@ class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager):
5365
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
5466
_create_attrs = RequiredOptional(required=("name",))
5567

68+
def get(
69+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
70+
) -> ProjectMergeRequestAwardEmoji:
71+
return cast(
72+
ProjectMergeRequestAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
73+
)
74+
5675

5776
class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
5877
pass
@@ -68,6 +87,13 @@ class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
6887
}
6988
_create_attrs = RequiredOptional(required=("name",))
7089

90+
def get(
91+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
92+
) -> ProjectMergeRequestNoteAwardEmoji:
93+
return cast(
94+
ProjectMergeRequestNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
95+
)
96+
7197

7298
class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject):
7399
pass
@@ -79,6 +105,11 @@ class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager):
79105
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
80106
_create_attrs = RequiredOptional(required=("name",))
81107

108+
def get(
109+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
110+
) -> ProjectSnippetAwardEmoji:
111+
return cast(ProjectSnippetAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
112+
82113

83114
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
84115
pass
@@ -93,3 +124,10 @@ class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
93124
"note_id": "id",
94125
}
95126
_create_attrs = RequiredOptional(required=("name",))
127+
128+
def get(
129+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
130+
) -> ProjectSnippetNoteAwardEmoji:
131+
return cast(
132+
ProjectSnippetNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
133+
)

gitlab/v4/objects/badges.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
2222
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
2323
_update_attrs = RequiredOptional(optional=("link_url", "image_url"))
2424

25+
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupBadge:
26+
return cast(GroupBadge, super().get(id=id, lazy=lazy, **kwargs))
27+
2528

2629
class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject):
2730
pass

gitlab/v4/objects/branches.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
35

@@ -19,6 +21,11 @@ class ProjectBranchManager(NoUpdateMixin, RESTManager):
1921
_from_parent_attrs = {"project_id": "id"}
2022
_create_attrs = RequiredOptional(required=("branch", "ref"))
2123

24+
def get(
25+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
26+
) -> ProjectBranch:
27+
return cast(ProjectBranch, super().get(id=id, lazy=lazy, **kwargs))
28+
2229

2330
class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
2431
_id_attr = "name"
@@ -40,3 +47,8 @@ class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
4047
"code_owner_approval_required",
4148
),
4249
)
50+
51+
def get(
52+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
53+
) -> ProjectProtectedBranch:
54+
return cast(ProjectProtectedBranch, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/clusters.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, cast, Dict, Optional
1+
from typing import Any, cast, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
44
from gitlab.base import RequiredOptional, RESTManager, RESTObject
@@ -57,6 +57,11 @@ def create(
5757
path = f"{self.path}/user"
5858
return cast(GroupCluster, CreateMixin.create(self, data, path=path, **kwargs))
5959

60+
def get(
61+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
62+
) -> GroupCluster:
63+
return cast(GroupCluster, super().get(id=id, lazy=lazy, **kwargs))
64+
6065

6166
class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject):
6267
pass
@@ -102,3 +107,8 @@ def create(
102107
"""
103108
path = f"{self.path}/user"
104109
return cast(ProjectCluster, CreateMixin.create(self, data, path=path, **kwargs))
110+
111+
def get(
112+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
113+
) -> ProjectCluster:
114+
return cast(ProjectCluster, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/commits.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
151151
optional=("author_email", "author_name"),
152152
)
153153

154+
def get(
155+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
156+
) -> ProjectCommit:
157+
return cast(ProjectCommit, super().get(id=id, lazy=lazy, **kwargs))
158+
154159

155160
class ProjectCommitComment(RESTObject):
156161
_id_attr = None

gitlab/v4/objects/container_registry.py

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

33
from gitlab import cli
44
from gitlab import exceptions as exc
@@ -60,3 +60,8 @@ def delete_in_bulk(self, name_regex_delete: str, **kwargs: Any) -> None:
6060
if TYPE_CHECKING:
6161
assert self.path is not None
6262
self.gitlab.http_delete(self.path, query_data=data, **kwargs)
63+
64+
def get(
65+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
66+
) -> ProjectRegistryTag:
67+
return cast(ProjectRegistryTag, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/custom_attributes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RESTManager, RESTObject
24
from gitlab.mixins import DeleteMixin, ObjectDeleteMixin, RetrieveMixin, SetMixin
35

@@ -20,6 +22,11 @@ class GroupCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTMana
2022
_obj_cls = GroupCustomAttribute
2123
_from_parent_attrs = {"group_id": "id"}
2224

25+
def get(
26+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
27+
) -> GroupCustomAttribute:
28+
return cast(GroupCustomAttribute, super().get(id=id, lazy=lazy, **kwargs))
29+
2330

2431
class ProjectCustomAttribute(ObjectDeleteMixin, RESTObject):
2532
_id_attr = "key"
@@ -30,6 +37,11 @@ class ProjectCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTMa
3037
_obj_cls = ProjectCustomAttribute
3138
_from_parent_attrs = {"project_id": "id"}
3239

40+
def get(
41+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
42+
) -> ProjectCustomAttribute:
43+
return cast(ProjectCustomAttribute, super().get(id=id, lazy=lazy, **kwargs))
44+
3345

3446
class UserCustomAttribute(ObjectDeleteMixin, RESTObject):
3547
_id_attr = "key"
@@ -39,3 +51,8 @@ class UserCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTManag
3951
_path = "/users/{user_id}/custom_attributes"
4052
_obj_cls = UserCustomAttribute
4153
_from_parent_attrs = {"user_id": "id"}
54+
55+
def get(
56+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
57+
) -> UserCustomAttribute:
58+
return cast(UserCustomAttribute, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/deployments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
35

@@ -28,3 +30,8 @@ class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTMana
2830
_create_attrs = RequiredOptional(
2931
required=("sha", "ref", "tag", "status", "environment")
3032
)
33+
34+
def get(
35+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
36+
) -> ProjectDeployment:
37+
return cast(ProjectDeployment, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/discussions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
35

@@ -30,6 +32,11 @@ class ProjectCommitDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
3032
_from_parent_attrs = {"project_id": "project_id", "commit_id": "id"}
3133
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
3234

35+
def get(
36+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
37+
) -> ProjectCommitDiscussion:
38+
return cast(ProjectCommitDiscussion, super().get(id=id, lazy=lazy, **kwargs))
39+
3340

3441
class ProjectIssueDiscussion(RESTObject):
3542
notes: ProjectIssueDiscussionNoteManager
@@ -41,6 +48,11 @@ class ProjectIssueDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
4148
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
4249
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
4350

51+
def get(
52+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
53+
) -> ProjectIssueDiscussion:
54+
return cast(ProjectIssueDiscussion, super().get(id=id, lazy=lazy, **kwargs))
55+
4456

4557
class ProjectMergeRequestDiscussion(SaveMixin, RESTObject):
4658
notes: ProjectMergeRequestDiscussionNoteManager
@@ -57,6 +69,13 @@ class ProjectMergeRequestDiscussionManager(
5769
)
5870
_update_attrs = RequiredOptional(required=("resolved",))
5971

72+
def get(
73+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
74+
) -> ProjectMergeRequestDiscussion:
75+
return cast(
76+
ProjectMergeRequestDiscussion, super().get(id=id, lazy=lazy, **kwargs)
77+
)
78+
6079

6180
class ProjectSnippetDiscussion(RESTObject):
6281
notes: ProjectSnippetDiscussionNoteManager
@@ -67,3 +86,8 @@ class ProjectSnippetDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
6786
_obj_cls = ProjectSnippetDiscussion
6887
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
6988
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
89+
90+
def get(
91+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
92+
) -> ProjectSnippetDiscussion:
93+
return cast(ProjectSnippetDiscussion, super().get(id=id, lazy=lazy, **kwargs))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy