diff options
author | John L. Villalovos <john@sodarock.com> | 2021-11-16 20:18:21 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2021-11-21 22:37:56 -0800 |
commit | d4adf8dfd2879b982ac1314e89df76cb61f2dbf9 (patch) | |
tree | 189014a2f82ba3be8bab965c8cda728b7f61525a /gitlab/v4/objects | |
parent | 9a451a892d37e0857af5c82c31a96d68ac161738 (diff) | |
download | gitlab-d4adf8dfd2879b982ac1314e89df76cb61f2dbf9.tar.gz |
chore: add type-hints to gitlab/v4/objects/epics.py
Diffstat (limited to 'gitlab/v4/objects')
-rw-r--r-- | gitlab/v4/objects/epics.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gitlab/v4/objects/epics.py b/gitlab/v4/objects/epics.py index b42ce98..38d244c 100644 --- a/gitlab/v4/objects/epics.py +++ b/gitlab/v4/objects/epics.py @@ -1,3 +1,5 @@ +from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union + from gitlab import exceptions as exc from gitlab import types from gitlab.base import RequiredOptional, RESTManager, RESTObject @@ -42,11 +44,17 @@ class GroupEpicManager(CRUDMixin, RESTManager): ) _types = {"labels": types.ListAttribute} + def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupEpic: + return cast(GroupEpic, super().get(id=id, lazy=lazy, **kwargs)) + class GroupEpicIssue(ObjectDeleteMixin, SaveMixin, RESTObject): _id_attr = "epic_issue_id" + # Define type for 'manager' here So mypy won't complain about + # 'self.manager.update()' call in the 'save' method. + manager: "GroupEpicIssueManager" - def save(self, **kwargs): + def save(self, **kwargs: Any) -> None: """Save the changes made to the object to the server. The object is updated to match what the server returns. @@ -78,7 +86,9 @@ class GroupEpicIssueManager( _update_attrs = RequiredOptional(optional=("move_before_id", "move_after_id")) @exc.on_http_error(exc.GitlabCreateError) - def create(self, data, **kwargs): + def create( + self, data: Optional[Dict[str, Any]] = None, **kwargs: Any + ) -> GroupEpicIssue: """Create a new object. Args: @@ -94,9 +104,13 @@ class GroupEpicIssueManager( RESTObject: A new instance of the manage object class build with the data sent by the server """ + if TYPE_CHECKING: + assert data is not None CreateMixin._check_missing_create_attrs(self, data) path = f"{self.path}/{data.pop('issue_id')}" server_data = self.gitlab.http_post(path, **kwargs) + if TYPE_CHECKING: + assert isinstance(server_data, dict) # The epic_issue_id attribute doesn't exist when creating the resource, # but is used everywhere elese. Let's create it to be consistent client # side |