Skip to content

Commit

Permalink
refactor: remove no-op id argument in GetWithoutIdMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch authored and JohnVillalovos committed Jun 26, 2022
1 parent 22ae101 commit 0f2a602
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 92 deletions.
4 changes: 1 addition & 3 deletions gitlab/mixins.py
Expand Up @@ -152,9 +152,7 @@ class GetWithoutIdMixin(HeadMixin, _RestManagerBase):
gitlab: gitlab.Gitlab

@exc.on_http_error(exc.GitlabGetError)
def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> base.RESTObject:
def get(self, **kwargs: Any) -> base.RESTObject:
"""Retrieve a single object.
Args:
Expand Down
6 changes: 2 additions & 4 deletions gitlab/v4/objects/appearance.py
Expand Up @@ -59,7 +59,5 @@ def update(
data = new_data.copy()
return super().update(id, data, **kwargs)

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ApplicationAppearance:
return cast(ApplicationAppearance, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ApplicationAppearance:
return cast(ApplicationAppearance, super().get(**kwargs))
18 changes: 9 additions & 9 deletions gitlab/v4/objects/export_import.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Optional, Union
from typing import Any, cast

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

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


class GroupImport(RESTObject):
Expand All @@ -38,8 +38,8 @@ class GroupImportManager(GetWithoutIdMixin, RESTManager):
_obj_cls = GroupImport
_from_parent_attrs = {"group_id": "id"}

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


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

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


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

def get(self, id: Optional[Union[int, str]] = None, **kwargs: Any) -> ProjectImport:
return cast(ProjectImport, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectImport:
return cast(ProjectImport, super().get(**kwargs))
20 changes: 7 additions & 13 deletions gitlab/v4/objects/merge_request_approvals.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, Union
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING

from gitlab import exceptions as exc
from gitlab.base import RESTManager, RESTObject
Expand Down Expand Up @@ -46,10 +46,8 @@ class ProjectApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
)
_update_uses_post = True

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

@exc.on_http_error(exc.GitlabUpdateError)
def set_approvers(
Expand Down Expand Up @@ -111,10 +109,8 @@ class ProjectMergeRequestApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTMan
_update_attrs = RequiredOptional(required=("approvals_required",))
_update_uses_post = True

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

@exc.on_http_error(exc.GitlabUpdateError)
def set_approvers(
Expand Down Expand Up @@ -254,7 +250,5 @@ class ProjectMergeRequestApprovalStateManager(GetWithoutIdMixin, RESTManager):
_obj_cls = ProjectMergeRequestApprovalState
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectMergeRequestApprovalState:
return cast(ProjectMergeRequestApprovalState, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectMergeRequestApprovalState:
return cast(ProjectMergeRequestApprovalState, super().get(**kwargs))
16 changes: 5 additions & 11 deletions gitlab/v4/objects/notification_settings.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Optional, Union
from typing import Any, cast

from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
Expand Down Expand Up @@ -39,10 +39,8 @@ class NotificationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
),
)

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


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

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


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

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectNotificationSettings:
def get(self, **kwargs: Any) -> ProjectNotificationSettings:
return cast(ProjectNotificationSettings, super().get(id=id, **kwargs))
12 changes: 4 additions & 8 deletions gitlab/v4/objects/pipelines.py
Expand Up @@ -251,10 +251,8 @@ class ProjectPipelineTestReportManager(GetWithoutIdMixin, RESTManager):
_obj_cls = ProjectPipelineTestReport
_from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}

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


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

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectPipelineTestReportSummary:
return cast(ProjectPipelineTestReportSummary, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectPipelineTestReportSummary:
return cast(ProjectPipelineTestReportSummary, super().get(**kwargs))
6 changes: 2 additions & 4 deletions gitlab/v4/objects/projects.py
Expand Up @@ -1033,7 +1033,5 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
_obj_cls = ProjectStorage
_from_parent_attrs = {"project_id": "id"}

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectStorage:
return cast(ProjectStorage, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectStorage:
return cast(ProjectStorage, super().get(**kwargs))
8 changes: 3 additions & 5 deletions gitlab/v4/objects/push_rules.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Optional, Union
from typing import Any, cast

from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import (
Expand Down Expand Up @@ -52,7 +52,5 @@ class ProjectPushRulesManager(
),
)

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectPushRules:
return cast(ProjectPushRules, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectPushRules:
return cast(ProjectPushRules, super().get(**kwargs))
6 changes: 2 additions & 4 deletions gitlab/v4/objects/settings.py
Expand Up @@ -116,7 +116,5 @@ def update(
data.pop("domain_whitelist")
return super().update(id, data, **kwargs)

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ApplicationSettings:
return cast(ApplicationSettings, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ApplicationSettings:
return cast(ApplicationSettings, super().get(**kwargs))
26 changes: 9 additions & 17 deletions gitlab/v4/objects/statistics.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Optional, Union
from typing import Any, cast

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

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


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

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


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

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


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

def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> ProjectIssuesStatistics:
return cast(ProjectIssuesStatistics, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> ProjectIssuesStatistics:
return cast(ProjectIssuesStatistics, super().get(**kwargs))
16 changes: 7 additions & 9 deletions gitlab/v4/objects/users.py
Expand Up @@ -3,7 +3,7 @@
https://docs.gitlab.com/ee/api/users.html
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
"""
from typing import Any, cast, Dict, List, Optional, Union
from typing import Any, cast, Dict, List, Union

import requests

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

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


class CurrentUser(RESTObject):
Expand All @@ -141,8 +139,8 @@ class CurrentUserManager(GetWithoutIdMixin, RESTManager):
_path = "/user"
_obj_cls = CurrentUser

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


class User(SaveMixin, ObjectDeleteMixin, RESTObject):
Expand Down Expand Up @@ -477,8 +475,8 @@ class UserStatusManager(GetWithoutIdMixin, RESTManager):
_obj_cls = UserStatus
_from_parent_attrs = {"user_id": "id"}

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


class UserActivitiesManager(ListMixin, RESTManager):
Expand Down
8 changes: 3 additions & 5 deletions tests/meta/test_ensure_type_hints.py
Expand Up @@ -70,13 +70,11 @@ def get(
"""

GET_WITHOUT_ID_METHOD_TEMPLATE = """
def get(
self, id: Optional[Union[int, str]] = None, **kwargs: Any
) -> {obj_cls.__name__}:
return cast({obj_cls.__name__}, super().get(id=id, **kwargs))
def get(self, **kwargs: Any) -> {obj_cls.__name__}:
return cast({obj_cls.__name__}, super().get(**kwargs))
You may also need to add the following imports:
from typing import Any, cast, Optional, Union"
from typing import Any, cast"
"""


Expand Down

0 comments on commit 0f2a602

Please sign in to comment.