Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8ba031

Browse files
chore: enable mypy check strict_equality
Enable the `mypy` `strict_equality` check.
1 parent e409811 commit d8ba031

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

gitlab/v4/objects/users.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
163163

164164
@cli.register_custom_action("User")
165165
@exc.on_http_error(exc.GitlabBlockError)
166-
def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
166+
def block(self, **kwargs: Any) -> bool:
167167
"""Block the user.
168168
169169
Args:
@@ -177,10 +177,13 @@ def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
177177
Whether the user status has been changed
178178
"""
179179
path = f"/users/{self.encoded_id}/block"
180-
server_data = self.manager.gitlab.http_post(path, **kwargs)
181-
if server_data is True:
182-
self._attrs["state"] = "blocked"
183-
return server_data
180+
# NOTE: Undocumented behavior of the GitLab API is that it returns a boolean
181+
server_data = cast(bool, self.manager.gitlab.http_post(path, **kwargs))
182+
if isinstance(server_data, bool):
183+
if server_data is True:
184+
self._attrs["state"] = "blocked"
185+
return server_data
186+
return False
184187

185188
@cli.register_custom_action("User")
186189
@exc.on_http_error(exc.GitlabFollowError)
@@ -220,7 +223,7 @@ def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
220223

221224
@cli.register_custom_action("User")
222225
@exc.on_http_error(exc.GitlabUnblockError)
223-
def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
226+
def unblock(self, **kwargs: Any) -> bool:
224227
"""Unblock the user.
225228
226229
Args:
@@ -234,10 +237,13 @@ def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
234237
Whether the user status has been changed
235238
"""
236239
path = f"/users/{self.encoded_id}/unblock"
237-
server_data = self.manager.gitlab.http_post(path, **kwargs)
238-
if server_data is True:
239-
self._attrs["state"] = "active"
240-
return server_data
240+
# NOTE: Undocumented behavior of the GitLab API is that it returns a boolean
241+
server_data = cast(bool, self.manager.gitlab.http_post(path, **kwargs))
242+
if isinstance(server_data, bool):
243+
if server_data is True:
244+
self._attrs["state"] = "active"
245+
return server_data
246+
return False
241247

242248
@cli.register_custom_action("User")
243249
@exc.on_http_error(exc.GitlabDeactivateError)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ disallow_incomplete_defs = true
1313
disallow_subclassing_any = true
1414
disallow_untyped_decorators = true
1515
disallow_untyped_defs = true
16+
no_implicit_reexport = true
17+
strict_equality = true
1618
warn_redundant_casts = true
1719
warn_unused_configs = true
1820
warn_unused_ignores = true
@@ -21,8 +23,6 @@ warn_unused_ignores = true
2123
# disallow_any_generics = true
2224
# disallow_untyped_calls = true
2325
# no_implicit_optional = true
24-
no_implicit_reexport = true
25-
# strict_equality = true
2626
# warn_return_any = true
2727

2828
[[tool.mypy.overrides]] # Overrides for currently untyped modules

tests/functional/api/test_users.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@ def test_create_user(gl, fixture_dir):
2828

2929

3030
def test_block_user(gl, user):
31-
user.block()
31+
result = user.block()
32+
assert result is True
3233
users = gl.users.list(blocked=True)
3334
assert user in users
3435

35-
user.unblock()
36+
# block again
37+
result = user.block()
38+
assert result is False
39+
40+
result = user.unblock()
41+
assert result is True
3642
users = gl.users.list(blocked=False)
3743
assert user in users
3844

45+
# unblock again
46+
result = user.unblock()
47+
assert result is False
48+
3949

4050
def test_ban_user(gl, user):
4151
user.ban()

0 commit comments

Comments
 (0)