Skip to content

Commit

Permalink
chore: add type-hints to gitlab/v4/objects/services.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVillalovos committed Nov 22, 2021
1 parent 00d7b20 commit 8da0b75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 15 additions & 5 deletions gitlab/v4/objects/services.py
@@ -1,3 +1,5 @@
from typing import Any, cast, Dict, List, Optional, Union

from gitlab import cli
from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import (
Expand Down Expand Up @@ -253,7 +255,9 @@ class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTM
"youtrack": (("issues_url", "project_url"), ("description", "push_events")),
}

def get(self, id, **kwargs):
def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectService:
"""Retrieve a single object.
Args:
Expand All @@ -270,11 +274,16 @@ def get(self, id, **kwargs):
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server cannot perform the request
"""
obj = super(ProjectServiceManager, self).get(id, **kwargs)
obj = cast(ProjectService, super(ProjectServiceManager, self).get(id, **kwargs))
obj.id = id
return obj

def update(self, id=None, new_data=None, **kwargs):
def update(
self,
id: Optional[Union[str, int]] = None,
new_data: Optional[Dict[str, Any]] = None,
**kwargs: Any
) -> Dict[str, Any]:
"""Update an object on the server.
Args:
Expand All @@ -290,11 +299,12 @@ def update(self, id=None, new_data=None, **kwargs):
GitlabUpdateError: If the server cannot perform the request
"""
new_data = new_data or {}
super(ProjectServiceManager, self).update(id, new_data, **kwargs)
result = super(ProjectServiceManager, self).update(id, new_data, **kwargs)
self.id = id
return result

@cli.register_custom_action("ProjectServiceManager")
def available(self, **kwargs):
def available(self, **kwargs: Any) -> List[str]:
"""List the services known by python-gitlab.
Returns:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -14,7 +14,6 @@ module = [
"docs.ext.*",
"gitlab.v4.objects.files",
"gitlab.v4.objects.labels",
"gitlab.v4.objects.services",
"gitlab.v4.objects.sidekiq",
"tests.functional.*",
"tests.functional.api.*",
Expand Down

0 comments on commit 8da0b75

Please sign in to comment.