Skip to content

Commit edd01a5

Browse files
igorp-collaboranejch
authored andcommitted
chore: Remove trivial get methods in preparation for generic Get mixin
Currently because the Get mixin is not generic every subclass has to implement its own `get` methods to type hint `get` method return beoynd the basic RESTObject. The upcoming PR will change Get mixin to use generics. This means it will be able to type hint the corresponding `_obj_cls` and no `get` method would need to be redefined. Because removing existing `get` methods modifies a lot of files split it in to a separate commit. Also remove the `tests/unit/meta/test_ensure_type_hints.py` file because testing subclasses for `get` methods is no longer relevant. Signed-off-by: Igor Ponomarev <igor.ponomarev@collabora.com>
1 parent 515a8a2 commit edd01a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+27
-960
lines changed

gitlab/client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ def auth(self) -> None:
397397
The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
398398
success.
399399
"""
400-
self.user = self._objects.CurrentUserManager(self).get()
400+
# pylint: disable=line-too-long
401+
self.user = self._objects.CurrentUserManager(self).get() # type: ignore[assignment]
401402

402403
if hasattr(self.user, "web_url") and hasattr(self.user, "username"):
403-
self._check_url(self.user.web_url, path=self.user.username)
404+
self._check_url(self.user.web_url, path=self.user.username) # type: ignore[union-attr]
404405

405406
def version(self) -> Tuple[str, str]:
406407
"""Returns the version and revision of the gitlab server.

gitlab/v4/objects/appearance.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, cast, Dict, Optional, Union
1+
from typing import Any, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
44
from gitlab.base import RESTManager, RESTObject
@@ -58,6 +58,3 @@ def update(
5858
new_data = new_data or {}
5959
data = new_data.copy()
6060
return super().update(id, data, **kwargs)
61-
62-
def get(self, **kwargs: Any) -> ApplicationAppearance:
63-
return cast(ApplicationAppearance, super().get(**kwargs))

gitlab/v4/objects/audit_events.py

-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
https://docs.gitlab.com/ee/api/audit_events.html
44
"""
55

6-
from typing import Any, cast, Union
7-
86
from gitlab.base import RESTManager, RESTObject
97
from gitlab.mixins import RetrieveMixin
108

@@ -29,9 +27,6 @@ class AuditEventManager(RetrieveMixin, RESTManager):
2927
_obj_cls = AuditEvent
3028
_list_filters = ("created_after", "created_before", "entity_type", "entity_id")
3129

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

3631
class GroupAuditEvent(RESTObject):
3732
_id_attr = "id"
@@ -43,11 +38,6 @@ class GroupAuditEventManager(RetrieveMixin, RESTManager):
4338
_from_parent_attrs = {"group_id": "id"}
4439
_list_filters = ("created_after", "created_before")
4540

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

5242
class ProjectAuditEvent(RESTObject):
5343
_id_attr = "id"
@@ -59,11 +49,6 @@ class ProjectAuditEventManager(RetrieveMixin, RESTManager):
5949
_from_parent_attrs = {"project_id": "id"}
6050
_list_filters = ("created_after", "created_before")
6151

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

6853
class ProjectAudit(ProjectAuditEvent):
6954
pass

gitlab/v4/objects/award_emojis.py

-48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
53
from gitlab.types import RequiredOptional
@@ -34,11 +32,6 @@ class GroupEpicAwardEmojiManager(NoUpdateMixin, RESTManager):
3432
_from_parent_attrs = {"group_id": "group_id", "epic_iid": "iid"}
3533
_create_attrs = RequiredOptional(required=("name",))
3634

37-
def get(
38-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
39-
) -> GroupEpicAwardEmoji:
40-
return cast(GroupEpicAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
41-
4235

4336
class GroupEpicNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
4437
pass
@@ -54,11 +47,6 @@ class GroupEpicNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
5447
}
5548
_create_attrs = RequiredOptional(required=("name",))
5649

57-
def get(
58-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
59-
) -> GroupEpicNoteAwardEmoji:
60-
return cast(GroupEpicNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
61-
6250

6351
class ProjectIssueAwardEmoji(ObjectDeleteMixin, RESTObject):
6452
pass
@@ -70,11 +58,6 @@ class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager):
7058
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
7159
_create_attrs = RequiredOptional(required=("name",))
7260

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

7962
class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
8063
pass
@@ -90,11 +73,6 @@ class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
9073
}
9174
_create_attrs = RequiredOptional(required=("name",))
9275

93-
def get(
94-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
95-
) -> ProjectIssueNoteAwardEmoji:
96-
return cast(ProjectIssueNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
97-
9876

9977
class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject):
10078
pass
@@ -106,13 +84,6 @@ class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager):
10684
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
10785
_create_attrs = RequiredOptional(required=("name",))
10886

109-
def get(
110-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
111-
) -> ProjectMergeRequestAwardEmoji:
112-
return cast(
113-
ProjectMergeRequestAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
114-
)
115-
11687

11788
class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
11889
pass
@@ -128,13 +99,6 @@ class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
12899
}
129100
_create_attrs = RequiredOptional(required=("name",))
130101

131-
def get(
132-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
133-
) -> ProjectMergeRequestNoteAwardEmoji:
134-
return cast(
135-
ProjectMergeRequestNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
136-
)
137-
138102

139103
class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject):
140104
pass
@@ -146,11 +110,6 @@ class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager):
146110
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
147111
_create_attrs = RequiredOptional(required=("name",))
148112

149-
def get(
150-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
151-
) -> ProjectSnippetAwardEmoji:
152-
return cast(ProjectSnippetAwardEmoji, super().get(id=id, lazy=lazy, **kwargs))
153-
154113

155114
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
156115
pass
@@ -165,10 +124,3 @@ class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
165124
"note_id": "id",
166125
}
167126
_create_attrs = RequiredOptional(required=("name",))
168-
169-
def get(
170-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
171-
) -> ProjectSnippetNoteAwardEmoji:
172-
return cast(
173-
ProjectSnippetNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
174-
)

gitlab/v4/objects/badges.py

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import BadgeRenderMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
53
from gitlab.types import RequiredOptional
@@ -23,9 +21,6 @@ class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
2321
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
2422
_update_attrs = RequiredOptional(optional=("link_url", "image_url"))
2523

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

3025
class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject):
3126
pass
@@ -37,8 +32,3 @@ class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
3732
_from_parent_attrs = {"project_id": "id"}
3833
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
3934
_update_attrs = RequiredOptional(optional=("link_url", "image_url"))
40-
41-
def get(
42-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
43-
) -> ProjectBadge:
44-
return cast(ProjectBadge, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/boards.py

-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
53
from gitlab.types import RequiredOptional
@@ -29,11 +27,6 @@ class GroupBoardListManager(CRUDMixin, RESTManager):
2927
)
3028
_update_attrs = RequiredOptional(required=("position",))
3129

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

3831
class GroupBoard(SaveMixin, ObjectDeleteMixin, RESTObject):
3932
lists: GroupBoardListManager
@@ -45,9 +38,6 @@ class GroupBoardManager(CRUDMixin, RESTManager):
4538
_from_parent_attrs = {"group_id": "id"}
4639
_create_attrs = RequiredOptional(required=("name",))
4740

48-
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupBoard:
49-
return cast(GroupBoard, super().get(id=id, lazy=lazy, **kwargs))
50-
5141

5242
class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):
5343
pass
@@ -62,11 +52,6 @@ class ProjectBoardListManager(CRUDMixin, RESTManager):
6252
)
6353
_update_attrs = RequiredOptional(required=("position",))
6454

65-
def get(
66-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
67-
) -> ProjectBoardList:
68-
return cast(ProjectBoardList, super().get(id=id, lazy=lazy, **kwargs))
69-
7055

7156
class ProjectBoard(SaveMixin, ObjectDeleteMixin, RESTObject):
7257
lists: ProjectBoardListManager
@@ -77,8 +62,3 @@ class ProjectBoardManager(CRUDMixin, RESTManager):
7762
_obj_cls = ProjectBoard
7863
_from_parent_attrs = {"project_id": "id"}
7964
_create_attrs = RequiredOptional(required=("name",))
80-
81-
def get(
82-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
83-
) -> ProjectBoard:
84-
return cast(ProjectBoard, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/branches.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import (
53
CRUDMixin,
@@ -28,11 +26,6 @@ class ProjectBranchManager(NoUpdateMixin, RESTManager):
2826
_from_parent_attrs = {"project_id": "id"}
2927
_create_attrs = RequiredOptional(required=("branch", "ref"))
3028

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

3730
class ProjectProtectedBranch(SaveMixin, ObjectDeleteMixin, RESTObject):
3831
_id_attr = "name"
@@ -56,8 +49,3 @@ class ProjectProtectedBranchManager(CRUDMixin, RESTManager):
5649
),
5750
)
5851
_update_method = UpdateMethod.PATCH
59-
60-
def get(
61-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
62-
) -> ProjectProtectedBranch:
63-
return cast(ProjectProtectedBranch, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/broadcast_messages.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
53
from gitlab.types import ArrayAttribute, RequiredOptional
@@ -33,8 +31,3 @@ class BroadcastMessageManager(CRUDMixin, RESTManager):
3331
)
3432
)
3533
_types = {"target_access_levels": ArrayAttribute}
36-
37-
def get(
38-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
39-
) -> BroadcastMessage:
40-
return cast(BroadcastMessage, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/bulk_imports.py

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin
53
from gitlab.types import RequiredOptional
@@ -24,9 +22,6 @@ class BulkImportManager(CreateMixin, RetrieveMixin, RESTManager):
2422
_create_attrs = RequiredOptional(required=("configuration", "entities"))
2523
_list_filters = ("sort", "status")
2624

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

3126
class BulkImportEntity(RefreshMixin, RESTObject):
3227
pass
@@ -38,11 +33,6 @@ class BulkImportEntityManager(RetrieveMixin, RESTManager):
3833
_from_parent_attrs = {"bulk_import_id": "id"}
3934
_list_filters = ("sort", "status")
4035

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

4737
class BulkImportAllEntity(RESTObject):
4838
pass

gitlab/v4/objects/ci_lint.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://docs.gitlab.com/ee/api/lint.html
44
"""
55

6-
from typing import Any, cast
6+
from typing import Any
77

88
from gitlab.base import RESTManager, RESTObject
99
from gitlab.cli import register_custom_action
@@ -59,9 +59,6 @@ class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
5959
required=("content",), optional=("dry_run", "include_jobs", "ref")
6060
)
6161

62-
def get(self, **kwargs: Any) -> ProjectCiLint:
63-
return cast(ProjectCiLint, super().get(**kwargs))
64-
6562
@register_custom_action(
6663
cls_names="ProjectCiLintManager",
6764
required=("content",),

gitlab/v4/objects/cluster_agents.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any, cast, Union
2-
31
from gitlab.base import RESTManager, RESTObject
42
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin, SaveMixin
53
from gitlab.types import RequiredOptional
@@ -19,8 +17,3 @@ class ProjectClusterAgentManager(NoUpdateMixin, RESTManager):
1917
_obj_cls = ProjectClusterAgent
2018
_from_parent_attrs = {"project_id": "id"}
2119
_create_attrs = RequiredOptional(required=("name",))
22-
23-
def get(
24-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
25-
) -> ProjectClusterAgent:
26-
return cast(ProjectClusterAgent, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/clusters.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, cast, Dict, Optional, Union
1+
from typing import Any, cast, Dict, Optional
22

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

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

6762
class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject):
6863
pass
@@ -108,8 +103,3 @@ def create(
108103
"""
109104
path = f"{self.path}/user"
110105
return cast(ProjectCluster, CreateMixin.create(self, data, path=path, **kwargs))
111-
112-
def get(
113-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
114-
) -> ProjectCluster:
115-
return cast(ProjectCluster, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/commits.py

-5
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
189189
"trailers",
190190
)
191191

192-
def get(
193-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
194-
) -> ProjectCommit:
195-
return cast(ProjectCommit, super().get(id=id, lazy=lazy, **kwargs))
196-
197192

198193
class ProjectCommitComment(RESTObject):
199194
_id_attr = None

0 commit comments

Comments
 (0)