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

Commit8dece89

Browse files
chore: enable mypy checkstrict_equality
Enable the `mypy` `strict_equality` check.
1 parente409811 commit8dece89

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

‎gitlab/v4/objects/users.py‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://docs.gitlab.com/ee/api/users.html
44
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
55
"""
6-
fromtypingimportAny,cast,Dict,List,Union
6+
fromtypingimportAny,cast,Dict,List,Optional,Union
77

88
importrequests
99

@@ -163,7 +163,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
163163

164164
@cli.register_custom_action("User")
165165
@exc.on_http_error(exc.GitlabBlockError)
166-
defblock(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
166+
defblock(self,**kwargs:Any)->Optional[bool]:
167167
"""Block the user.
168168
169169
Args:
@@ -177,10 +177,19 @@ 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-
ifserver_dataisTrue:
182-
self._attrs["state"]="blocked"
183-
returnserver_data
180+
# NOTE: Undocumented behavior of the GitLab API is that it returns a
181+
# boolean or None
182+
server_data=cast(
183+
Optional[bool],self.manager.gitlab.http_post(path,**kwargs)
184+
)
185+
ifserver_dataisNone:
186+
returnNone
187+
ifisinstance(server_data,bool):
188+
ifserver_dataisTrue:
189+
self._attrs["state"]="blocked"
190+
returnserver_data
191+
# Shouldn't get here ...
192+
returnNone
184193

185194
@cli.register_custom_action("User")
186195
@exc.on_http_error(exc.GitlabFollowError)
@@ -220,7 +229,7 @@ def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
220229

221230
@cli.register_custom_action("User")
222231
@exc.on_http_error(exc.GitlabUnblockError)
223-
defunblock(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
232+
defunblock(self,**kwargs:Any)->Optional[bool]:
224233
"""Unblock the user.
225234
226235
Args:
@@ -234,10 +243,19 @@ def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
234243
Whether the user status has been changed
235244
"""
236245
path=f"/users/{self.encoded_id}/unblock"
237-
server_data=self.manager.gitlab.http_post(path,**kwargs)
238-
ifserver_dataisTrue:
239-
self._attrs["state"]="active"
240-
returnserver_data
246+
# NOTE: Undocumented behavior of the GitLab API is that it returns a
247+
# boolean or None
248+
server_data=cast(
249+
Optional[bool],self.manager.gitlab.http_post(path,**kwargs)
250+
)
251+
ifserver_dataisNone:
252+
returnNone
253+
ifisinstance(server_data,bool):
254+
ifserver_dataisTrue:
255+
self._attrs["state"]="active"
256+
returnserver_data
257+
# Shouldn't get here ...
258+
returnNone
241259

242260
@cli.register_custom_action("User")
243261
@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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,26 @@ def test_create_user(gl, fixture_dir):
2828

2929

3030
deftest_block_user(gl,user):
31-
user.block()
31+
result=user.block()
32+
assertresultisTrue
3233
users=gl.users.list(blocked=True)
3334
assertuserinusers
3435

35-
user.unblock()
36+
# block again
37+
result=user.block()
38+
# Trying to block an already blocked user returns None
39+
assertresultisNone
40+
41+
result=user.unblock()
42+
assertresultisTrue
3643
users=gl.users.list(blocked=False)
3744
assertuserinusers
3845

46+
# unblock again
47+
result=user.unblock()
48+
# Trying to unblock an already blocked user returns False
49+
assertresultisFalse
50+
3951

4052
deftest_ban_user(gl,user):
4153
user.ban()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp