8000 chore: enable mypy check `strict_equality` by JohnVillalovos · Pull Request #2146 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

chore: enable mypy check strict_equality #2146

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 13 additions & 5 deletions gitlab/v4/objects/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
https://docs.gitlab.com/ee/api/users.html
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
"""
from typing import Any, cast, Dict, List, Union
from typing import Any, cast, Dict, List, Optional, Union

import requests

Expand Down Expand Up @@ -163,7 +163,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]:
def block(self, **kwargs: Any) -> Optional[bool]:
"""Block the user.

Args:
Expand All @@ -177,7 +177,11 @@ def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
Whether the user status has been changed
"""
path = f"/users/{self.encoded_id}/block"
server_data = self.manager.gitlab.http_post(path, **kwargs)
# NOTE: Undocumented behavior of the GitLab API is that it returns a
# boolean or None
server_data = cast(
Optional[bool], self.manager.gitlab.http_post(path, **kwargs)
)
if server_data is True:
self._attrs["state"] = "blocked"
return server_data
Expand Down Expand Up @@ -220,7 +224,7 @@ def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:

@cli.register_custom_action("User")
@exc.on_http_error(exc.GitlabUnblockError)
def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
def unblock(self, **kwargs: Any) -> Optional[bool]:
"""Unblock the user.

Args:
Expand All @@ -234,7 +238,11 @@ def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
Whether the user status has been changed
"""
path = f"/users/{self.encoded_id}/unblock"
server_data = self.manager.gitlab.http_post(path, **kwargs)
# NOTE: Undocumented behavior of the GitLab API is that it returns a
# boolean or None
server_data = cast(
Optional[bool], self.manager.gitlab.http_post(path, **kwargs)
)
if server_data is True:
self._attrs["state"] = "active"
return server_data
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_reexport = true
strict_equality = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true
Expand All @@ -21,8 +23,6 @@ warn_unused_ignores = true
# disallow_any_generics = true
# disallow_untyped_calls = true
# no_implicit_optional = true
no_implicit_reexport = true
# strict_equality = true
# warn_return_any = true

[[tool.mypy.overrides]] # Overrides for currently untyped modules
Expand Down
16 changes: 14 additions & 2 deletions tests/functional/api/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@ def test_create_user(gl, fixture_dir):


def test_block_user(gl, user):
user.block()
result = user.block()
assert result is True
users = gl.users.list(blocked=True)
assert user in users

user.unblock()
# block again
result = user.block()
# Trying to block an already blocked user returns None
assert result is None

result = user.unblock()
assert result is True
users = gl.users.list(blocked=False)
assert user in users

# unblock again
result = user.unblock()
# Trying to unblock an already blocked user returns False
assert result is False


def test_ban_user(gl, user):
user.ban()
Expand Down
0