Skip to content

Commit

Permalink
Merge pull request #1681 from python-gitlab/jlvillal/mypy_ensure_type…
Browse files Browse the repository at this point in the history
…_hints

Ensure get() methods have correct type-hints
  • Loading branch information
nejch committed Nov 16, 2021
2 parents a553ee7 + 46773a8 commit 0951989
Show file tree
Hide file tree
Showing 25 changed files with 437 additions and 6 deletions.
15 changes: 15 additions & 0 deletions gitlab/v4/objects/audit_events.py
Expand Up @@ -2,6 +2,8 @@
GitLab API:
https://docs.gitlab.com/ee/api/audit_events.html
"""
from typing import Any, cast, Union

from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import RetrieveMixin

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

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


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

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


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

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


class ProjectAudit(ProjectAuditEvent):
pass
Expand Down
38 changes: 38 additions & 0 deletions gitlab/v4/objects/award_emojis.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin

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

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


class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass
Expand All @@ -42,6 +49,11 @@ class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
}
_create_attrs = RequiredOptional(required=("name",))

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


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

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


class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass
Expand All @@ -68,6 +87,13 @@ class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
}
_create_attrs = RequiredOptional(required=("name",))

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


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

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


class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
pass
Expand All @@ -93,3 +124,10 @@ class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
"note_id": "id",
}
_create_attrs = RequiredOptional(required=("name",))

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectSnippetNoteAwardEmoji:
return cast(
ProjectSnippetNoteAwardEmoji, super().get(id=id, lazy=lazy, **kwargs)
)
3 changes: 3 additions & 0 deletions gitlab/v4/objects/badges.py
Expand Up @@ -22,6 +22,9 @@ class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
_update_attrs = RequiredOptional(optional=("link_url", "image_url"))

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


class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject):
pass
Expand Down
12 changes: 12 additions & 0 deletions gitlab/v4/objects/branches.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin

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

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


class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
_id_attr = "name"
Expand All @@ -40,3 +47,8 @@ class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
"code_owner_approval_required",
),
)

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectProtectedBranch:
return cast(ProjectProtectedBranch, super().get(id=id, lazy=lazy, **kwargs))
12 changes: 11 additions & 1 deletion gitlab/v4/objects/clusters.py
@@ -1,4 +1,4 @@
from typing import Any, cast, Dict, Optional
from typing import Any, cast, Dict, Optional, Union

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

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


class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject):
pass
Expand Down Expand Up @@ -102,3 +107,8 @@ def create(
"""
path = f"{self.path}/user"
return cast(ProjectCluster, CreateMixin.create(self, data, path=path, **kwargs))

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectCluster:
return cast(ProjectCluster, super().get(id=id, lazy=lazy, **kwargs))
5 changes: 5 additions & 0 deletions gitlab/v4/objects/commits.py
Expand Up @@ -151,6 +151,11 @@ class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
optional=("author_email", "author_name"),
)

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


class ProjectCommitComment(RESTObject):
_id_attr = None
Expand Down
7 changes: 6 additions & 1 deletion gitlab/v4/objects/container_registry.py
@@ -1,4 +1,4 @@
from typing import Any, TYPE_CHECKING
from typing import Any, cast, TYPE_CHECKING, Union

from gitlab import cli
from gitlab import exceptions as exc
Expand Down Expand Up @@ -60,3 +60,8 @@ def delete_in_bulk(self, name_regex_delete: str, **kwargs: Any) -> None:
if TYPE_CHECKING:
assert self.path is not None
self.gitlab.http_delete(self.path, query_data=data, **kwargs)

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectRegistryTag:
return cast(ProjectRegistryTag, super().get(id=id, lazy=lazy, **kwargs))
17 changes: 17 additions & 0 deletions gitlab/v4/objects/custom_attributes.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import DeleteMixin, ObjectDeleteMixin, RetrieveMixin, SetMixin

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

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


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

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


class UserCustomAttribute(ObjectDeleteMixin, RESTObject):
_id_attr = "key"
Expand All @@ -39,3 +51,8 @@ class UserCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTManag
_path = "/users/{user_id}/custom_attributes"
_obj_cls = UserCustomAttribute
_from_parent_attrs = {"user_id": "id"}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> UserCustomAttribute:
return cast(UserCustomAttribute, super().get(id=id, lazy=lazy, **kwargs))
7 changes: 7 additions & 0 deletions gitlab/v4/objects/deployments.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin

Expand Down Expand Up @@ -28,3 +30,8 @@ class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTMana
_create_attrs = RequiredOptional(
required=("sha", "ref", "tag", "status", "environment")
)

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectDeployment:
return cast(ProjectDeployment, super().get(id=id, lazy=lazy, **kwargs))
24 changes: 24 additions & 0 deletions gitlab/v4/objects/discussions.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin

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

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


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

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


class ProjectMergeRequestDiscussion(SaveMixin, RESTObject):
notes: ProjectMergeRequestDiscussionNoteManager
Expand All @@ -57,6 +69,13 @@ class ProjectMergeRequestDiscussionManager(
)
_update_attrs = RequiredOptional(required=("resolved",))

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


class ProjectSnippetDiscussion(RESTObject):
notes: ProjectSnippetDiscussionNoteManager
Expand All @@ -67,3 +86,8 @@ class ProjectSnippetDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
_obj_cls = ProjectSnippetDiscussion
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectSnippetDiscussion:
return cast(ProjectSnippetDiscussion, super().get(id=id, lazy=lazy, **kwargs))
7 changes: 6 additions & 1 deletion gitlab/v4/objects/environments.py
@@ -1,4 +1,4 @@
from typing import Any, Dict, Union
from typing import Any, cast, Dict, Union

import requests

Expand Down Expand Up @@ -48,3 +48,8 @@ class ProjectEnvironmentManager(
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("name",), optional=("external_url",))
_update_attrs = RequiredOptional(optional=("name", "external_url"))

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

0 comments on commit 0951989

Please sign in to comment.