Skip to content

chore: add type-hints to multiple files in gitlab/v4/objects/ #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gitlab/v4/objects/broadcast_messages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin

Expand All @@ -21,3 +23,8 @@ class BroadcastMessageManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
optional=("message", "starts_at", "ends_at", "color", "font")
)

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> BroadcastMessage:
return cast(BroadcastMessage, super().get(id=id, lazy=lazy, **kwargs))
14 changes: 11 additions & 3 deletions gitlab/v4/objects/keys.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, cast, Optional, TYPE_CHECKING, Union

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

Expand All @@ -15,12 +17,18 @@ class KeyManager(GetMixin, RESTManager):
_path = "/keys"
_obj_cls = Key

def get(self, id=None, **kwargs):
def get(
self, id: Optional[Union[int, str]] = None, lazy: bool = False, **kwargs: Any
) -> Key:
if id is not None:
return super(KeyManager, self).get(id, **kwargs)
return cast(Key, super(KeyManager, self).get(id, lazy=lazy, **kwargs))

if "fingerprint" not in kwargs:
raise AttributeError("Missing attribute: id or fingerprint")

if TYPE_CHECKING:
assert self.path is not None
server_data = self.gitlab.http_get(self.path, **kwargs)
return self._obj_cls(self, server_data)
if TYPE_CHECKING:
assert isinstance(server_data, dict)
return cast(Key, self._obj_cls(self, server_data))
2 changes: 1 addition & 1 deletion gitlab/v4/objects/merge_trains.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class ProjectMergeTrainManager(ListMixin, RESTManager):
_path = "/projects/%(project_id)s/merge_trains"
_obj_cls = ProjectMergeTrain
_from_parent_attrs = {"project_id": "id"}
_list_filters = "scope"
_list_filters = ("scope",)
5 changes: 5 additions & 0 deletions gitlab/v4/objects/namespaces.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, cast, Union

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

Expand All @@ -15,3 +17,6 @@ class NamespaceManager(RetrieveMixin, RESTManager):
_path = "/namespaces"
_obj_cls = Namespace
_list_filters = ("search",)

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

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin

Expand Down Expand Up @@ -30,3 +32,8 @@ class ProjectPagesDomainManager(CRUDMixin, RESTManager):
required=("domain",), optional=("certificate", "key")
)
_update_attrs = RequiredOptional(optional=("certificate", "key"))

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

from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin

Expand All @@ -17,3 +19,8 @@ class ProjectTriggerManager(CRUDMixin, RESTManager):
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("description",))
_update_attrs = RequiredOptional(required=("description",))

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectTrigger:
return cast(ProjectTrigger, super().get(id=id, lazy=lazy, **kwargs))
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ ignore_errors = true

[[tool.mypy.overrides]] # Overrides to negate above patterns
module = [
"gitlab.v4.objects.access_requests",
"gitlab.v4.objects.applications",
"gitlab.v4.objects.broadcast_messages",
"gitlab.v4.objects.deployments",
"gitlab.v4.objects.groups",
"gitlab.v4.objects.keys",
"gitlab.v4.objects.merge_requests",
"gitlab.v4.objects.merge_trains",
"gitlab.v4.objects.namespaces",
"gitlab.v4.objects.pages",
"gitlab.v4.objects.personal_access_tokens",
"gitlab.v4.objects.project_access_tokens",
"gitlab.v4.objects.projects",
"gitlab.v4.objects.tags",
"gitlab.v4.objects.templates",
"gitlab.v4.objects.triggers",
"gitlab.v4.objects.users",
]
ignore_errors = false
Expand Down