- Notifications
You must be signed in to change notification settings - Fork673
chore: add type-hints to gitlab/v4/objects/users.py#1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, RESTObjectList | ||
from gitlab.mixins import ( | ||
CreateMixin, | ||
CRUDMixin, | ||
@@ -129,7 +133,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabBlockError) | ||
def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Block the user. | ||
Args: | ||
@@ -150,7 +154,7 @@ def block(self, **kwargs): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabFollowError) | ||
def follow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Follow the user. | ||
Args: | ||
@@ -168,7 +172,7 @@ def follow(self, **kwargs): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabUnfollowError) | ||
def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Unfollow the user. | ||
Args: | ||
@@ -186,7 +190,7 @@ def unfollow(self, **kwargs): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabUnblockError) | ||
def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Unblock the user. | ||
Args: | ||
@@ -207,7 +211,7 @@ def unblock(self, **kwargs): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabDeactivateError) | ||
def deactivate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Deactivate the user. | ||
Args: | ||
@@ -228,7 +232,7 @@ def deactivate(self, **kwargs): | ||
@cli.register_custom_action("User") | ||
@exc.on_http_error(exc.GitlabActivateError) | ||
def activate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
"""Activate the user. | ||
Args: | ||
@@ -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)) | ||
Comment on lines +326 to +327 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. question: I already merged this for projects but now it has me thinking, is there any way to avoid adding all this boilerplate for typing? There will be alot of these I imagine if as we go module by module, and I guess will need to be copy/pasted for a lot of mixin usage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I have tried and tried again and tried again... But so far I can't figure out a way to do it. If you can figure it out it will be awesome! There are ways to do it if you return a This will help editors and the type-checker in knowing that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Oh, you will probably like my idea for handling At the moment my best solution for that seems to be adding a | ||
class ProjectUser(RESTObject): | ||
pass | ||
@@ -470,7 +477,7 @@ class UserProjectManager(ListMixin, CreateMixin, RESTManager): | ||
"id_before", | ||
) | ||
def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | ||
"""Retrieve a list of objects. | ||
Args: | ||