diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 71ba8210c..f2df27d89 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -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: diff --git a/gitlab/v4/objects/appearance.py b/gitlab/v4/objects/appearance.py index db4b551ed..88ab6215d 100644 --- a/gitlab/v4/objects/appearance.py +++ b/gitlab/v4/objects/appearance.py @@ -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)) diff --git a/gitlab/v4/objects/export_import.py b/gitlab/v4/objects/export_import.py index a275164ac..5e07661b6 100644 --- a/gitlab/v4/objects/export_import.py +++ b/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 @@ -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): @@ -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): @@ -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): @@ -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)) diff --git a/gitlab/v4/objects/merge_request_approvals.py b/gitlab/v4/objects/merge_request_approvals.py index eb243c7b4..8df6cd78d 100644 --- a/gitlab/v4/objects/merge_request_approvals.py +++ b/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 @@ -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( @@ -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( @@ -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)) diff --git a/gitlab/v4/objects/notification_settings.py b/gitlab/v4/objects/notification_settings.py index d3cd4cbae..4b38549a3 100644 --- a/gitlab/v4/objects/notification_settings.py +++ b/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 @@ -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): @@ -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)) @@ -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)) diff --git a/gitlab/v4/objects/pipelines.py b/gitlab/v4/objects/pipelines.py index 0db82a34d..80a45fe25 100644 --- a/gitlab/v4/objects/pipelines.py +++ b/gitlab/v4/objects/pipelines.py @@ -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): @@ -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)) diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index f32cf2257..4893788b2 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -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)) diff --git a/gitlab/v4/objects/push_rules.py b/gitlab/v4/objects/push_rules.py index ce75eacce..d1fe81c17 100644 --- a/gitlab/v4/objects/push_rules.py +++ b/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 ( @@ -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)) diff --git a/gitlab/v4/objects/settings.py b/gitlab/v4/objects/settings.py index 6171833d3..16b1041c5 100644 --- a/gitlab/v4/objects/settings.py +++ b/gitlab/v4/objects/settings.py @@ -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)) diff --git a/gitlab/v4/objects/statistics.py b/gitlab/v4/objects/statistics.py index 24c17a585..3176674f4 100644 --- a/gitlab/v4/objects/statistics.py +++ b/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 @@ -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): @@ -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): @@ -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): @@ -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)) diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index bef9fbec0..69d72e9d7 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -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 @@ -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): @@ -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): @@ -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): diff --git a/tests/meta/test_ensure_type_hints.py b/tests/meta/test_ensure_type_hints.py index 10f945c63..f55ca45d0 100644 --- a/tests/meta/test_ensure_type_hints.py +++ b/tests/meta/test_ensure_type_hints.py @@ -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" """