Skip to content

Commit

Permalink
chore: add type-hints to gitlab/v4/objects/users.py
Browse files Browse the repository at this point in the history
Adding type-hints to gitlab/v4/objects/users.py
  • Loading branch information
JohnVillalovos committed Sep 7, 2021
1 parent b8a47ba commit 88988e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 15 additions & 8 deletions gitlab/v4/objects/users.py
@@ -1,7 +1,11 @@
from typing import Any, cast, Dict, List, Union

import requests

from gitlab import cli
from gitlab import exceptions as exc
from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
from gitlab.mixins import (
CreateMixin,
CRUDMixin,
Expand Down Expand Up @@ -129,7 +133,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabBlockError)
def block(self, **kwargs):
def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Block the user.
Args:
Expand All @@ -150,7 +154,7 @@ def block(self, **kwargs):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabFollowError)
def follow(self, **kwargs):
def follow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Follow the user.
Args:
Expand All @@ -168,7 +172,7 @@ def follow(self, **kwargs):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabUnfollowError)
def unfollow(self, **kwargs):
def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Unfollow the user.
Args:
Expand All @@ -186,7 +190,7 @@ def unfollow(self, **kwargs):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabUnblockError)
def unblock(self, **kwargs):
def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Unblock the user.
Args:
Expand All @@ -207,7 +211,7 @@ def unblock(self, **kwargs):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabDeactivateError)
def deactivate(self, **kwargs):
def deactivate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Deactivate the user.
Args:
Expand All @@ -228,7 +232,7 @@ def deactivate(self, **kwargs):

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabActivateError)
def activate(self, **kwargs):
def activate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
"""Activate the user.
Args:
Expand Down Expand Up @@ -319,6 +323,9 @@ class UserManager(CRUDMixin, RESTManager):
)
_types = {"confirm": types.LowercaseStringAttribute, "avatar": types.ImageAttribute}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> User:
return cast(User, super().get(id=id, lazy=lazy, **kwargs))


class ProjectUser(RESTObject):
pass
Expand Down Expand Up @@ -470,7 +477,7 @@ class UserProjectManager(ListMixin, CreateMixin, RESTManager):
"id_before",
)

def list(self, **kwargs):
def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]:
"""Retrieve a list of objects.
Args:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -23,7 +23,8 @@ ignore_errors = true

[[tool.mypy.overrides]] # Overrides to negate above patterns
module = [
"gitlab.v4.objects.projects"
"gitlab.v4.objects.projects",
"gitlab.v4.objects.users"
]
ignore_errors = false

Expand Down

0 comments on commit 88988e3

Please sign in to comment.