33https://docs.gitlab.com/ee/api/users.html
44https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
55"""
6- from typing import Any ,cast ,Dict ,List ,Union
6+ from typing import Any ,cast ,Dict ,List ,Optional , Union
77
88import requests
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- def block (self ,** kwargs :Any )-> Union [ Dict [ str , Any ], requests . Response ]:
166+ def block (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 """
179179path = 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
181+ # boolean or None
182+ server_data = cast (
183+ Optional [bool ],self .manager .gitlab .http_post (path ,** kwargs )
184+ )
185+ if server_data is None :
186+ return None
187+ if isinstance (server_data ,bool ):
188+ if server_data is True :
189+ self ._attrs ["state" ]= "blocked"
190+ return server_data
191+ # Shouldn't get here ...
192+ return None
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- def unblock (self ,** kwargs :Any )-> Union [ Dict [ str , Any ], requests . Response ]:
232+ def unblock (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 """
236245path = 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
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+ if server_data is None :
252+ return None
253+ if isinstance (server_data ,bool ):
254+ if server_data is True :
255+ self ._attrs ["state" ]= "active"
256+ return server_data
257+ # Shouldn't get here ...
258+ return None
241259
242260@cli .register_custom_action ("User" )
243261@exc .on_http_error (exc .GitlabDeactivateError )