Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
nejch merged 1 commit intopython-gitlab:masterfromJohnVillalovos:jlvillal/mypy_v4_obj_users
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletionsgitlab/v4/objects/users.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
from gitlab.mixins import (
CreateMixin,
CRUDMixin,
Expand DownExpand 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 DownExpand 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))
Comment on lines +326 to +327
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The 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 aself object. But since we are returningself._obj_cls() it doesn't seem like things are smart enough to understand that yet. Well at least notmypy

This will help editors and the type-checker in knowing thatgl.users.get() returns aUser object. Otherwise it will think it returns aRESTObject which isn't as useful.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, you will probably like my idea for handlinggl.users.list() even less 😜

At the moment my best solution for that seems to be adding aUserList class or something like that. I haven't figured it out yet but thinking about it.



class ProjectUser(RESTObject):
pass
Expand DownExpand 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 deletionpyproject.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
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

[8]ページ先頭

©2009-2025 Movatter.jp