Skip to content

Commit 7753fa2

Browse files
authored
Merge pull request #1515 from JohnVillalovos/jlvillal/mypy_v4_obj_users
chore: add type-hints to gitlab/v4/objects/users.py
2 parents 9656a16 + 88988e3 commit 7753fa2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

gitlab/v4/objects/users.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from typing import Any, cast, Dict, List, Union
2+
3+
import requests
4+
15
from gitlab import cli
26
from gitlab import exceptions as exc
37
from gitlab import types
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
8+
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
59
from gitlab.mixins import (
610
CreateMixin,
711
CRUDMixin,
@@ -129,7 +133,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
129133

130134
@cli.register_custom_action("User")
131135
@exc.on_http_error(exc.GitlabBlockError)
132-
def block(self, **kwargs):
136+
def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
133137
"""Block the user.
134138
135139
Args:
@@ -150,7 +154,7 @@ def block(self, **kwargs):
150154

151155
@cli.register_custom_action("User")
152156
@exc.on_http_error(exc.GitlabFollowError)
153-
def follow(self, **kwargs):
157+
def follow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
154158
"""Follow the user.
155159
156160
Args:
@@ -168,7 +172,7 @@ def follow(self, **kwargs):
168172

169173
@cli.register_custom_action("User")
170174
@exc.on_http_error(exc.GitlabUnfollowError)
171-
def unfollow(self, **kwargs):
175+
def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
172176
"""Unfollow the user.
173177
174178
Args:
@@ -186,7 +190,7 @@ def unfollow(self, **kwargs):
186190

187191
@cli.register_custom_action("User")
188192
@exc.on_http_error(exc.GitlabUnblockError)
189-
def unblock(self, **kwargs):
193+
def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
190194
"""Unblock the user.
191195
192196
Args:
@@ -207,7 +211,7 @@ def unblock(self, **kwargs):
207211

208212
@cli.register_custom_action("User")
209213
@exc.on_http_error(exc.GitlabDeactivateError)
210-
def deactivate(self, **kwargs):
214+
def deactivate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
211215
"""Deactivate the user.
212216
213217
Args:
@@ -228,7 +232,7 @@ def deactivate(self, **kwargs):
228232

229233
@cli.register_custom_action("User")
230234
@exc.on_http_error(exc.GitlabActivateError)
231-
def activate(self, **kwargs):
235+
def activate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
232236
"""Activate the user.
233237
234238
Args:
@@ -319,6 +323,9 @@ class UserManager(CRUDMixin, RESTManager):
319323
)
320324
_types = {"confirm": types.LowercaseStringAttribute, "avatar": types.ImageAttribute}
321325

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

323330
class ProjectUser(RESTObject):
324331
pass
@@ -470,7 +477,7 @@ class UserProjectManager(ListMixin, CreateMixin, RESTManager):
470477
"id_before",
471478
)
472479

473-
def list(self, **kwargs):
480+
def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]:
474481
"""Retrieve a list of objects.
475482
476483
Args:

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ ignore_errors = true
2323

2424
[[tool.mypy.overrides]] # Overrides to negate above patterns
2525
module = [
26-
"gitlab.v4.objects.projects"
26+
"gitlab.v4.objects.projects",
27+
"gitlab.v4.objects.users"
2728
]
2829
ignore_errors = false
2930

0 commit comments

Comments
 (0)