diff options
| author | Nejc Habjan <hab.nejc@gmail.com> | 2021-11-07 22:55:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-07 22:55:23 +0100 |
| commit | cf801d8e643cb6717ea8495b9463908ce12eef34 (patch) | |
| tree | 3f1b9a0574430272bc5e7ede26f77a235b789c4b /gitlab | |
| parent | f3688dcf2dea33f5e17e456f86f8f50ff9312deb (diff) | |
| parent | 8b75a7712dd1665d4b3eabb0c4594e80ab5e5308 (diff) | |
| download | gitlab-cf801d8e643cb6717ea8495b9463908ce12eef34.tar.gz | |
Merge pull request #1674 from python-gitlab/jlvillal/mypy_small_files_1
chore: add type-hints to multiple files in gitlab/v4/objects/
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/v4/objects/broadcast_messages.py | 7 | ||||
| -rw-r--r-- | gitlab/v4/objects/keys.py | 14 | ||||
| -rw-r--r-- | gitlab/v4/objects/merge_trains.py | 2 | ||||
| -rw-r--r-- | gitlab/v4/objects/namespaces.py | 5 | ||||
| -rw-r--r-- | gitlab/v4/objects/pages.py | 7 | ||||
| -rw-r--r-- | gitlab/v4/objects/triggers.py | 7 |
6 files changed, 38 insertions, 4 deletions
diff --git a/gitlab/v4/objects/broadcast_messages.py b/gitlab/v4/objects/broadcast_messages.py index 7784997..7e28be6 100644 --- a/gitlab/v4/objects/broadcast_messages.py +++ b/gitlab/v4/objects/broadcast_messages.py @@ -1,3 +1,5 @@ +from typing import Any, cast, Union + from gitlab.base import RequiredOptional, RESTManager, RESTObject from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin @@ -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)) diff --git a/gitlab/v4/objects/keys.py b/gitlab/v4/objects/keys.py index 7f8fa0e..46f6894 100644 --- a/gitlab/v4/objects/keys.py +++ b/gitlab/v4/objects/keys.py @@ -1,3 +1,5 @@ +from typing import Any, cast, Optional, TYPE_CHECKING, Union + from gitlab.base import RESTManager, RESTObject from gitlab.mixins import GetMixin @@ -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)) diff --git a/gitlab/v4/objects/merge_trains.py b/gitlab/v4/objects/merge_trains.py index 4b23892..d66c993 100644 --- a/gitlab/v4/objects/merge_trains.py +++ b/gitlab/v4/objects/merge_trains.py @@ -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",) diff --git a/gitlab/v4/objects/namespaces.py b/gitlab/v4/objects/namespaces.py index deee281..91a1850 100644 --- a/gitlab/v4/objects/namespaces.py +++ b/gitlab/v4/objects/namespaces.py @@ -1,3 +1,5 @@ +from typing import Any, cast, Union + from gitlab.base import RESTManager, RESTObject from gitlab.mixins import RetrieveMixin @@ -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)) diff --git a/gitlab/v4/objects/pages.py b/gitlab/v4/objects/pages.py index 709d9f0..fc192fc 100644 --- a/gitlab/v4/objects/pages.py +++ b/gitlab/v4/objects/pages.py @@ -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 @@ -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)) diff --git a/gitlab/v4/objects/triggers.py b/gitlab/v4/objects/triggers.py index f203d93..6ff2517 100644 --- a/gitlab/v4/objects/triggers.py +++ b/gitlab/v4/objects/triggers.py @@ -1,3 +1,5 @@ +from typing import Any, cast, Union + from gitlab.base import RequiredOptional, RESTManager, RESTObject from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin @@ -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)) |
