Skip to content

Commit 0f2a602

Browse files
nejchJohnVillalovos
authored andcommitted
refactor: remove no-op id argument in GetWithoutIdMixin
1 parent 22ae101 commit 0f2a602

12 files changed

+54
-92
lines changed

gitlab/mixins.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ class GetWithoutIdMixin(HeadMixin, _RestManagerBase):
152152
gitlab: gitlab.Gitlab
153153

154154
@exc.on_http_error(exc.GitlabGetError)
155-
def get(
156-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
157-
) -> base.RESTObject:
155+
def get(self, **kwargs: Any) -> base.RESTObject:
158156
"""Retrieve a single object.
159157
160158
Args:

gitlab/v4/objects/appearance.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,5 @@ def update(
5959
data = new_data.copy()
6060
return super().update(id, data, **kwargs)
6161

62-
def get(
63-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
64-
) -> ApplicationAppearance:
65-
return cast(ApplicationAppearance, super().get(id=id, **kwargs))
62+
def get(self, **kwargs: Any) -> ApplicationAppearance:
63+
return cast(ApplicationAppearance, super().get(**kwargs))

gitlab/v4/objects/export_import.py

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

33
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import CreateMixin, DownloadMixin, GetWithoutIdMixin, RefreshMixin
@@ -25,8 +25,8 @@ class GroupExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
2525
_obj_cls = GroupExport
2626
_from_parent_attrs = {"group_id": "id"}
2727

28-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> GroupExport:
29-
return cast(GroupExport, super().get(id=id, **kwargs))
28+
def get(self, **kwargs: Any) -> GroupExport:
29+
return cast(GroupExport, super().get(**kwargs))
3030

3131

3232
class GroupImport(RESTObject):
@@ -38,8 +38,8 @@ class GroupImportManager(GetWithoutIdMixin, RESTManager):
3838
_obj_cls = GroupImport
3939
_from_parent_attrs = {"group_id": "id"}
4040

41-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> GroupImport:
42-
return cast(GroupImport, super().get(id=id, **kwargs))
41+
def get(self, **kwargs: Any) -> GroupImport:
42+
return cast(GroupImport, super().get(**kwargs))
4343

4444

4545
class ProjectExport(DownloadMixin, RefreshMixin, RESTObject):
@@ -52,8 +52,8 @@ class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
5252
_from_parent_attrs = {"project_id": "id"}
5353
_create_attrs = RequiredOptional(optional=("description",))
5454

55-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> ProjectExport:
56-
return cast(ProjectExport, super().get(id=id, **kwargs))
55+
def get(self, **kwargs: Any) -> ProjectExport:
56+
return cast(ProjectExport, super().get(**kwargs))
5757

5858

5959
class ProjectImport(RefreshMixin, RESTObject):
@@ -65,5 +65,5 @@ class ProjectImportManager(GetWithoutIdMixin, RESTManager):
6565
_obj_cls = ProjectImport
6666
_from_parent_attrs = {"project_id": "id"}
6767

68-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> ProjectImport:
69-
return cast(ProjectImport, super().get(id=id, **kwargs))
68+
def get(self, **kwargs: Any) -> ProjectImport:
69+
return cast(ProjectImport, super().get(**kwargs))

gitlab/v4/objects/merge_request_approvals.py

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

33
from gitlab import exceptions as exc
44
from gitlab.base import RESTManager, RESTObject
@@ -46,10 +46,8 @@ class ProjectApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
4646
)
4747
_update_uses_post = True
4848

49-
def get(
50-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
51-
) -> ProjectApproval:
52-
return cast(ProjectApproval, super().get(id=id, **kwargs))
49+
def get(self, **kwargs: Any) -> ProjectApproval:
50+
return cast(ProjectApproval, super().get(**kwargs))
5351

5452
@exc.on_http_error(exc.GitlabUpdateError)
5553
def set_approvers(
@@ -111,10 +109,8 @@ class ProjectMergeRequestApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTMan
111109
_update_attrs = RequiredOptional(required=("approvals_required",))
112110
_update_uses_post = True
113111

114-
def get(
115-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
116-
) -> ProjectMergeRequestApproval:
117-
return cast(ProjectMergeRequestApproval, super().get(id=id, **kwargs))
112+
def get(self, **kwargs: Any) -> ProjectMergeRequestApproval:
113+
return cast(ProjectMergeRequestApproval, super().get(**kwargs))
118114

119115
@exc.on_http_error(exc.GitlabUpdateError)
120116
def set_approvers(
@@ -254,7 +250,5 @@ class ProjectMergeRequestApprovalStateManager(GetWithoutIdMixin, RESTManager):
254250
_obj_cls = ProjectMergeRequestApprovalState
255251
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
256252

257-
def get(
258-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
259-
) -> ProjectMergeRequestApprovalState:
260-
return cast(ProjectMergeRequestApprovalState, super().get(id=id, **kwargs))
253+
def get(self, **kwargs: Any) -> ProjectMergeRequestApprovalState:
254+
return cast(ProjectMergeRequestApprovalState, super().get(**kwargs))

gitlab/v4/objects/notification_settings.py

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

33
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
@@ -39,10 +39,8 @@ class NotificationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
3939
),
4040
)
4141

42-
def get(
43-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
44-
) -> NotificationSettings:
45-
return cast(NotificationSettings, super().get(id=id, **kwargs))
42+
def get(self, **kwargs: Any) -> NotificationSettings:
43+
return cast(NotificationSettings, super().get(**kwargs))
4644

4745

4846
class GroupNotificationSettings(NotificationSettings):
@@ -54,9 +52,7 @@ class GroupNotificationSettingsManager(NotificationSettingsManager):
5452
_obj_cls = GroupNotificationSettings
5553
_from_parent_attrs = {"group_id": "id"}
5654

57-
def get(
58-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
59-
) -> GroupNotificationSettings:
55+
def get(self, **kwargs: Any) -> GroupNotificationSettings:
6056
return cast(GroupNotificationSettings, super().get(id=id, **kwargs))
6157

6258

@@ -69,7 +65,5 @@ class ProjectNotificationSettingsManager(NotificationSettingsManager):
6965
_obj_cls = ProjectNotificationSettings
7066
_from_parent_attrs = {"project_id": "id"}
7167

72-
def get(
73-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
74-
) -> ProjectNotificationSettings:
68+
def get(self, **kwargs: Any) -> ProjectNotificationSettings:
7569
return cast(ProjectNotificationSettings, super().get(id=id, **kwargs))

gitlab/v4/objects/pipelines.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,8 @@ class ProjectPipelineTestReportManager(GetWithoutIdMixin, RESTManager):
251251
_obj_cls = ProjectPipelineTestReport
252252
_from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}
253253

254-
def get(
255-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
256-
) -> ProjectPipelineTestReport:
257-
return cast(ProjectPipelineTestReport, super().get(id=id, **kwargs))
254+
def get(self, **kwargs: Any) -> ProjectPipelineTestReport:
255+
return cast(ProjectPipelineTestReport, super().get(**kwargs))
258256

259257

260258
class ProjectPipelineTestReportSummary(RESTObject):
@@ -266,7 +264,5 @@ class ProjectPipelineTestReportSummaryManager(GetWithoutIdMixin, RESTManager):
266264
_obj_cls = ProjectPipelineTestReportSummary
267265
_from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}
268266

269-
def get(
270-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
271-
) -> ProjectPipelineTestReportSummary:
272-
return cast(ProjectPipelineTestReportSummary, super().get(id=id, **kwargs))
267+
def get(self, **kwargs: Any) -> ProjectPipelineTestReportSummary:
268+
return cast(ProjectPipelineTestReportSummary, super().get(**kwargs))

gitlab/v4/objects/projects.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,5 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
10331033
_obj_cls = ProjectStorage
10341034
_from_parent_attrs = {"project_id": "id"}
10351035

1036-
def get(
1037-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
1038-
) -> ProjectStorage:
1039-
return cast(ProjectStorage, super().get(id=id, **kwargs))
1036+
def get(self, **kwargs: Any) -> ProjectStorage:
1037+
return cast(ProjectStorage, super().get(**kwargs))

gitlab/v4/objects/push_rules.py

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

33
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import (
@@ -52,7 +52,5 @@ class ProjectPushRulesManager(
5252
),
5353
)
5454

55-
def get(
56-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
57-
) -> ProjectPushRules:
58-
return cast(ProjectPushRules, super().get(id=id, **kwargs))
55+
def get(self, **kwargs: Any) -> ProjectPushRules:
56+
return cast(ProjectPushRules, super().get(**kwargs))

gitlab/v4/objects/settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,5 @@ def update(
116116
data.pop("domain_whitelist")
117117
return super().update(id, data, **kwargs)
118118

119-
def get(
120-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
121-
) -> ApplicationSettings:
122-
return cast(ApplicationSettings, super().get(id=id, **kwargs))
119+
def get(self, **kwargs: Any) -> ApplicationSettings:
120+
return cast(ApplicationSettings, super().get(**kwargs))

gitlab/v4/objects/statistics.py

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

33
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import GetWithoutIdMixin, RefreshMixin
@@ -24,10 +24,8 @@ class ProjectAdditionalStatisticsManager(GetWithoutIdMixin, RESTManager):
2424
_obj_cls = ProjectAdditionalStatistics
2525
_from_parent_attrs = {"project_id": "id"}
2626

27-
def get(
28-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
29-
) -> ProjectAdditionalStatistics:
30-
return cast(ProjectAdditionalStatistics, super().get(id=id, **kwargs))
27+
def get(self, **kwargs: Any) -> ProjectAdditionalStatistics:
28+
return cast(ProjectAdditionalStatistics, super().get(**kwargs))
3129

3230

3331
class IssuesStatistics(RefreshMixin, RESTObject):
@@ -38,10 +36,8 @@ class IssuesStatisticsManager(GetWithoutIdMixin, RESTManager):
3836
_path = "/issues_statistics"
3937
_obj_cls = IssuesStatistics
4038

41-
def get(
42-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
43-
) -> IssuesStatistics:
44-
return cast(IssuesStatistics, super().get(id=id, **kwargs))
39+
def get(self, **kwargs: Any) -> IssuesStatistics:
40+
return cast(IssuesStatistics, super().get(**kwargs))
4541

4642

4743
class GroupIssuesStatistics(RefreshMixin, RESTObject):
@@ -53,10 +49,8 @@ class GroupIssuesStatisticsManager(GetWithoutIdMixin, RESTManager):
5349
_obj_cls = GroupIssuesStatistics
5450
_from_parent_attrs = {"group_id": "id"}
5551

56-
def get(
57-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
58-
) -> GroupIssuesStatistics:
59-
return cast(GroupIssuesStatistics, super().get(id=id, **kwargs))
52+
def get(self, **kwargs: Any) -> GroupIssuesStatistics:
53+
return cast(GroupIssuesStatistics, super().get(**kwargs))
6054

6155

6256
class ProjectIssuesStatistics(RefreshMixin, RESTObject):
@@ -68,7 +62,5 @@ class ProjectIssuesStatisticsManager(GetWithoutIdMixin, RESTManager):
6862
_obj_cls = ProjectIssuesStatistics
6963
_from_parent_attrs = {"project_id": "id"}
7064

71-
def get(
72-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
73-
) -> ProjectIssuesStatistics:
74-
return cast(ProjectIssuesStatistics, super().get(id=id, **kwargs))
65+
def get(self, **kwargs: Any) -> ProjectIssuesStatistics:
66+
return cast(ProjectIssuesStatistics, super().get(**kwargs))

gitlab/v4/objects/users.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://docs.gitlab.com/ee/api/users.html
44
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
55
"""
6-
from typing import Any, cast, Dict, List, Optional, Union
6+
from typing import Any, cast, Dict, List, Union
77

88
import requests
99

@@ -121,10 +121,8 @@ class CurrentUserStatusManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
121121
_obj_cls = CurrentUserStatus
122122
_update_attrs = RequiredOptional(optional=("emoji", "message"))
123123

124-
def get(
125-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
126-
) -> CurrentUserStatus:
127-
return cast(CurrentUserStatus, super().get(id=id, **kwargs))
124+
def get(self, **kwargs: Any) -> CurrentUserStatus:
125+
return cast(CurrentUserStatus, super().get(**kwargs))
128126

129127

130128
class CurrentUser(RESTObject):
@@ -141,8 +139,8 @@ class CurrentUserManager(GetWithoutIdMixin, RESTManager):
141139
_path = "/user"
142140
_obj_cls = CurrentUser
143141

144-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> CurrentUser:
145-
return cast(CurrentUser, super().get(id=id, **kwargs))
142+
def get(self, **kwargs: Any) -> CurrentUser:
143+
return cast(CurrentUser, super().get(**kwargs))
146144

147145

148146
class User(SaveMixin, ObjectDeleteMixin, RESTObject):
@@ -477,8 +475,8 @@ class UserStatusManager(GetWithoutIdMixin, RESTManager):
477475
_obj_cls = UserStatus
478476
_from_parent_attrs = {"user_id": "id"}
479477

480-
def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> UserStatus:
481-
return cast(UserStatus, super().get(id=id, **kwargs))
478+
def get(self, **kwargs: Any) -> UserStatus:
479+
return cast(UserStatus, super().get(**kwargs))
482480

483481

484482
class UserActivitiesManager(ListMixin, RESTManager):

tests/meta/test_ensure_type_hints.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ def get(
7070
"""
7171

7272
GET_WITHOUT_ID_METHOD_TEMPLATE = """
73-
def get(
74-
self, id: Optional[Union[int, str]] = None, **kwargs: Any
75-
) -> {obj_cls.__name__}:
76-
return cast({obj_cls.__name__}, super().get(id=id, **kwargs))
73+
def get(self, **kwargs: Any) -> {obj_cls.__name__}:
74+
return cast({obj_cls.__name__}, super().get(**kwargs))
7775
7876
You may also need to add the following imports:
79-
from typing import Any, cast, Optional, Union"
77+
from typing import Any, cast"
8078
"""
8179

8280

0 commit comments

Comments
 (0)