Skip to content

Commit 8b75a77

Browse files
chore: add type-hints to multiple files in gitlab/v4/objects/
Add and/or check type-hints for the following files gitlab.v4.objects.access_requests gitlab.v4.objects.applications gitlab.v4.objects.broadcast_messages gitlab.v4.objects.deployments gitlab.v4.objects.keys 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.tags gitlab.v4.objects.templates gitlab.v4.objects.triggers Add a 'get' method with the correct type for Managers derived from GetMixin.
1 parent f3688dc commit 8b75a77

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

gitlab/v4/objects/broadcast_messages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
35

@@ -21,3 +23,8 @@ class BroadcastMessageManager(CRUDMixin, RESTManager):
2123
_update_attrs = RequiredOptional(
2224
optional=("message", "starts_at", "ends_at", "color", "font")
2325
)
26+
27+
def get(
28+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
29+
) -> BroadcastMessage:
30+
return cast(BroadcastMessage, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/keys.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Optional, TYPE_CHECKING, Union
2+
13
from gitlab.base import RESTManager, RESTObject
24
from gitlab.mixins import GetMixin
35

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

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

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

29+
if TYPE_CHECKING:
30+
assert self.path is not None
2531
server_data = self.gitlab.http_get(self.path, **kwargs)
26-
return self._obj_cls(self, server_data)
32+
if TYPE_CHECKING:
33+
assert isinstance(server_data, dict)
34+
return cast(Key, self._obj_cls(self, server_data))

gitlab/v4/objects/merge_trains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class ProjectMergeTrainManager(ListMixin, RESTManager):
1515
_path = "/projects/%(project_id)s/merge_trains"
1616
_obj_cls = ProjectMergeTrain
1717
_from_parent_attrs = {"project_id": "id"}
18-
_list_filters = "scope"
18+
_list_filters = ("scope",)

gitlab/v4/objects/namespaces.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RESTManager, RESTObject
24
from gitlab.mixins import RetrieveMixin
35

@@ -15,3 +17,6 @@ class NamespaceManager(RetrieveMixin, RESTManager):
1517
_path = "/namespaces"
1618
_obj_cls = Namespace
1719
_list_filters = ("search",)
20+
21+
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Namespace:
22+
return cast(Namespace, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/pages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin
35

@@ -30,3 +32,8 @@ class ProjectPagesDomainManager(CRUDMixin, RESTManager):
3032
required=("domain",), optional=("certificate", "key")
3133
)
3234
_update_attrs = RequiredOptional(optional=("certificate", "key"))
35+
36+
def get(
37+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
38+
) -> ProjectPagesDomain:
39+
return cast(ProjectPagesDomain, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/triggers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Union
2+
13
from gitlab.base import RequiredOptional, RESTManager, RESTObject
24
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
35

@@ -17,3 +19,8 @@ class ProjectTriggerManager(CRUDMixin, RESTManager):
1719
_from_parent_attrs = {"project_id": "id"}
1820
_create_attrs = RequiredOptional(required=("description",))
1921
_update_attrs = RequiredOptional(required=("description",))
22+
23+
def get(
24+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
25+
) -> ProjectTrigger:
26+
return cast(ProjectTrigger, super().get(id=id, lazy=lazy, **kwargs))

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ ignore_errors = true
2323

2424
[[tool.mypy.overrides]] # Overrides to negate above patterns
2525
module = [
26+
"gitlab.v4.objects.access_requests",
27+
"gitlab.v4.objects.applications",
28+
"gitlab.v4.objects.broadcast_messages",
29+
"gitlab.v4.objects.deployments",
2630
"gitlab.v4.objects.groups",
31+
"gitlab.v4.objects.keys",
2732
"gitlab.v4.objects.merge_requests",
33+
"gitlab.v4.objects.merge_trains",
34+
"gitlab.v4.objects.namespaces",
35+
"gitlab.v4.objects.pages",
36+
"gitlab.v4.objects.personal_access_tokens",
37+
"gitlab.v4.objects.project_access_tokens",
2838
"gitlab.v4.objects.projects",
39+
"gitlab.v4.objects.tags",
40+
"gitlab.v4.objects.templates",
41+
"gitlab.v4.objects.triggers",
2942
"gitlab.v4.objects.users",
3043
]
3144
ignore_errors = false

0 commit comments

Comments
 (0)