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

Commit97f8233

Browse files
chore: correct type-hints forhttp_get/http_post derived values
The methods `http_get()` and `http_post()` can also return a `list`.Update the code to handle that case.Closes:#2158
1 parenta46d9bf commit97f8233

File tree

12 files changed

+64
-80
lines changed

12 files changed

+64
-80
lines changed

‎gitlab/client.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
f"api-usage.html#pagination"
4545
)
4646

47+
HttpResponseType=Union[Dict[str,Any],List[Any],requests.Response]
48+
4749

4850
classGitlab:
4951
"""Represents a GitLab server connection.
@@ -409,7 +411,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
409411
post_data= {"content":content}
410412
data=self.http_post("/ci/lint",post_data=post_data,**kwargs)
411413
ifTYPE_CHECKING:
412-
assertnotisinstance(data,requests.Response)
414+
assertisinstance(data,dict)
413415
return (data["status"]=="valid",data["errors"])
414416

415417
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
@@ -436,7 +438,7 @@ def markdown(
436438
post_data["project"]=project
437439
data=self.http_post("/markdown",post_data=post_data,**kwargs)
438440
ifTYPE_CHECKING:
439-
assertnotisinstance(data,requests.Response)
441+
assertisinstance(data,dict)
440442
assertisinstance(data["html"],str)
441443
returndata["html"]
442444

@@ -477,7 +479,7 @@ def set_license(self, license: str, **kwargs: Any) -> Dict[str, Any]:
477479
data= {"license":license}
478480
result=self.http_post("/license",post_data=data,**kwargs)
479481
ifTYPE_CHECKING:
480-
assertnotisinstance(result,requests.Response)
482+
assertisinstance(result,dict)
481483
returnresult
482484

483485
def_set_auth_info(self)->None:
@@ -776,7 +778,7 @@ def http_get(
776778
streamed:bool=False,
777779
raw:bool=False,
778780
**kwargs:Any,
779-
)->Union[Dict[str,Any],requests.Response]:
781+
)->HttpResponseType:
780782
"""Make a GET request to the Gitlab server.
781783
782784
Args:
@@ -956,7 +958,7 @@ def http_post(
956958
raw:bool=False,
957959
files:Optional[Dict[str,Any]]=None,
958960
**kwargs:Any,
959-
)->Union[Dict[str,Any],requests.Response]:
961+
)->HttpResponseType:
960962
"""Make a POST request to the Gitlab server.
961963
962964
Args:

‎gitlab/mixins.py‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
importrequests
3333

3434
importgitlab
35+
importgitlab.clientasgl_client
3536
fromgitlabimportbase,cli
3637
fromgitlabimportexceptionsasexc
3738
fromgitlabimportutils
@@ -138,7 +139,7 @@ def get(
138139
returnself._obj_cls(self, {self._obj_cls._id_attr:id},lazy=lazy)
139140
server_data=self.gitlab.http_get(path,**kwargs)
140141
ifTYPE_CHECKING:
141-
assertnotisinstance(server_data,requests.Response)
142+
assertisinstance(server_data,dict)
142143
returnself._obj_cls(self,server_data,lazy=lazy)
143144

144145

@@ -170,7 +171,7 @@ def get(self, **kwargs: Any) -> base.RESTObject:
170171
assertself.pathisnotNone
171172
server_data=self.gitlab.http_get(self.path,**kwargs)
172173
ifTYPE_CHECKING:
173-
assertnotisinstance(server_data,requests.Response)
174+
assertisinstance(server_data,dict)
174175
assertself._obj_clsisnotNone
175176
returnself._obj_cls(self,server_data)
176177

@@ -204,7 +205,7 @@ def refresh(self, **kwargs: Any) -> None:
204205
path=self.manager.path
205206
server_data=self.manager.gitlab.http_get(path,**kwargs)
206207
ifTYPE_CHECKING:
207-
assertnotisinstance(server_data,requests.Response)
208+
assertisinstance(server_data,dict)
208209
self._update_attrs(server_data)
209210

210211

@@ -309,7 +310,7 @@ def create(
309310
path=kwargs.pop("path",self.path)
310311
server_data=self.gitlab.http_post(path,post_data=data,files=files,**kwargs)
311312
ifTYPE_CHECKING:
312-
assertnotisinstance(server_data,requests.Response)
313+
assertisinstance(server_data,dict)
313314
assertself._obj_clsisnotNone
314315
returnself._obj_cls(self,server_data)
315316

@@ -326,7 +327,7 @@ class UpdateMixin(_RestManagerBase):
326327

327328
def_get_update_method(
328329
self,
329-
)->Callable[...,Union[Dict[str,Any],requests.Response]]:
330+
)->Callable[...,gl_client.HttpResponseType]:
330331
"""Return the HTTP method to use.
331332
332333
Returns:
@@ -375,7 +376,7 @@ def update(
375376
http_method=self._get_update_method()
376377
result=http_method(path,post_data=new_data,files=files,**kwargs)
377378
ifTYPE_CHECKING:
378-
assertnotisinstance(result,requests.Response)
379+
assertisinstance(result,dict)
379380
returnresult
380381

381382

@@ -562,7 +563,7 @@ def user_agent_detail(self, **kwargs: Any) -> Dict[str, Any]:
562563
path=f"{self.manager.path}/{self.encoded_id}/user_agent_detail"
563564
result=self.manager.gitlab.http_get(path,**kwargs)
564565
ifTYPE_CHECKING:
565-
assertnotisinstance(result,requests.Response)
566+
assertisinstance(result,dict)
566567
returnresult
567568

568569

@@ -675,7 +676,7 @@ def subscribe(self, **kwargs: Any) -> None:
675676
path=f"{self.manager.path}/{self.encoded_id}/subscribe"
676677
server_data=self.manager.gitlab.http_post(path,**kwargs)
677678
ifTYPE_CHECKING:
678-
assertnotisinstance(server_data,requests.Response)
679+
assertisinstance(server_data,dict)
679680
self._update_attrs(server_data)
680681

681682
@cli.register_custom_action(
@@ -695,7 +696,7 @@ def unsubscribe(self, **kwargs: Any) -> None:
695696
path=f"{self.manager.path}/{self.encoded_id}/unsubscribe"
696697
server_data=self.manager.gitlab.http_post(path,**kwargs)
697698
ifTYPE_CHECKING:
698-
assertnotisinstance(server_data,requests.Response)
699+
assertisinstance(server_data,dict)
699700
self._update_attrs(server_data)
700701

701702

@@ -754,7 +755,7 @@ def time_stats(self, **kwargs: Any) -> Dict[str, Any]:
754755
path=f"{self.manager.path}/{self.encoded_id}/time_stats"
755756
result=self.manager.gitlab.http_get(path,**kwargs)
756757
ifTYPE_CHECKING:
757-
assertnotisinstance(result,requests.Response)
758+
assertisinstance(result,dict)
758759
returnresult
759760

760761
@cli.register_custom_action(("ProjectIssue","ProjectMergeRequest"), ("duration",))
@@ -774,7 +775,7 @@ def time_estimate(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
774775
data= {"duration":duration}
775776
result=self.manager.gitlab.http_post(path,post_data=data,**kwargs)
776777
ifTYPE_CHECKING:
777-
assertnotisinstance(result,requests.Response)
778+
assertisinstance(result,dict)
778779
returnresult
779780

780781
@cli.register_custom_action(("ProjectIssue","ProjectMergeRequest"))
@@ -792,7 +793,7 @@ def reset_time_estimate(self, **kwargs: Any) -> Dict[str, Any]:
792793
path=f"{self.manager.path}/{self.encoded_id}/reset_time_estimate"
793794
result=self.manager.gitlab.http_post(path,**kwargs)
794795
ifTYPE_CHECKING:
795-
assertnotisinstance(result,requests.Response)
796+
assertisinstance(result,dict)
796797
returnresult
797798

798799
@cli.register_custom_action(("ProjectIssue","ProjectMergeRequest"), ("duration",))
@@ -812,7 +813,7 @@ def add_spent_time(self, duration: str, **kwargs: Any) -> Dict[str, Any]:
812813
data= {"duration":duration}
813814
result=self.manager.gitlab.http_post(path,post_data=data,**kwargs)
814815
ifTYPE_CHECKING:
815-
assertnotisinstance(result,requests.Response)
816+
assertisinstance(result,dict)
816817
returnresult
817818

818819
@cli.register_custom_action(("ProjectIssue","ProjectMergeRequest"))
@@ -830,7 +831,7 @@ def reset_spent_time(self, **kwargs: Any) -> Dict[str, Any]:
830831
path=f"{self.manager.path}/{self.encoded_id}/reset_spent_time"
831832
result=self.manager.gitlab.http_post(path,**kwargs)
832833
ifTYPE_CHECKING:
833-
assertnotisinstance(result,requests.Response)
834+
assertisinstance(result,dict)
834835
returnresult
835836

836837

@@ -864,7 +865,7 @@ def participants(self, **kwargs: Any) -> Dict[str, Any]:
864865
path=f"{self.manager.path}/{self.encoded_id}/participants"
865866
result=self.manager.gitlab.http_get(path,**kwargs)
866867
ifTYPE_CHECKING:
867-
assertnotisinstance(result,requests.Response)
868+
assertisinstance(result,dict)
868869
returnresult
869870

870871

@@ -892,7 +893,7 @@ def render(self, link_url: str, image_url: str, **kwargs: Any) -> Dict[str, Any]
892893
data= {"link_url":link_url,"image_url":image_url}
893894
result=self.gitlab.http_get(path,data,**kwargs)
894895
ifTYPE_CHECKING:
895-
assertnotisinstance(result,requests.Response)
896+
assertisinstance(result,dict)
896897
returnresult
897898

898899

@@ -907,7 +908,7 @@ class PromoteMixin(_RestObjectBase):
907908

908909
def_get_update_method(
909910
self,
910-
)->Callable[...,Union[Dict[str,Any],requests.Response]]:
911+
)->Callable[...,gl_client.HttpResponseType]:
911912
"""Return the HTTP method to use.
912913
913914
Returns:
@@ -939,5 +940,5 @@ def promote(self, **kwargs: Any) -> Dict[str, Any]:
939940
http_method=self._get_update_method()
940941
result=http_method(path,**kwargs)
941942
ifTYPE_CHECKING:
942-
assertnotisinstance(result,requests.Response)
943+
assertisinstance(result,dict)
943944
returnresult

‎gitlab/v4/objects/commits.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
fromtypingimportAny,cast,Dict,List,Optional,TYPE_CHECKING,Union
22

3-
importrequests
4-
53
importgitlab
64
fromgitlabimportcli
75
fromgitlabimportexceptionsasexc
@@ -107,9 +105,7 @@ def merge_requests(
107105

108106
@cli.register_custom_action("ProjectCommit", ("branch",))
109107
@exc.on_http_error(exc.GitlabRevertError)
110-
defrevert(
111-
self,branch:str,**kwargs:Any
112-
)->Union[Dict[str,Any],requests.Response]:
108+
defrevert(self,branch:str,**kwargs:Any)->gitlab.client.HttpResponseType:
113109
"""Revert a commit on a given branch.
114110
115111
Args:
@@ -129,7 +125,7 @@ def revert(
129125

130126
@cli.register_custom_action("ProjectCommit")
131127
@exc.on_http_error(exc.GitlabGetError)
132-
defsignature(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
128+
defsignature(self,**kwargs:Any)->gitlab.client.HttpResponseType:
133129
"""Get the signature of the commit.
134130
135131
Args:

‎gitlab/v4/objects/deploy_keys.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
fromtypingimportAny,cast,Dict,Union
2-
3-
importrequests
1+
fromtypingimportAny,cast,Union
42

3+
importgitlab
54
fromgitlabimportcli
65
fromgitlabimportexceptionsasexc
76
fromgitlab.baseimportRESTManager,RESTObject
@@ -38,9 +37,7 @@ class ProjectKeyManager(CRUDMixin, RESTManager):
3837

3938
@cli.register_custom_action("ProjectKeyManager", ("key_id",))
4039
@exc.on_http_error(exc.GitlabProjectDeployKeyError)
41-
defenable(
42-
self,key_id:int,**kwargs:Any
43-
)->Union[Dict[str,Any],requests.Response]:
40+
defenable(self,key_id:int,**kwargs:Any)->gitlab.client.HttpResponseType:
4441
"""Enable a deploy key for a project.
4542
4643
Args:

‎gitlab/v4/objects/environments.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
fromtypingimportAny,cast,Dict,Union
2-
3-
importrequests
1+
fromtypingimportAny,cast,Union
42

3+
importgitlab
54
fromgitlabimportcli
65
fromgitlabimportexceptionsasexc
76
fromgitlab.baseimportRESTManager,RESTObject
@@ -26,7 +25,7 @@
2625
classProjectEnvironment(SaveMixin,ObjectDeleteMixin,RESTObject):
2726
@cli.register_custom_action("ProjectEnvironment")
2827
@exc.on_http_error(exc.GitlabStopError)
29-
defstop(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
28+
defstop(self,**kwargs:Any)->gitlab.client.HttpResponseType:
3029
"""Stop the environment.
3130
3231
Args:

‎gitlab/v4/objects/groups.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
fromtypingimportAny,BinaryIO,cast,Dict,List,Optional,Type,TYPE_CHECKING,Union
22

3-
importrequests
4-
53
importgitlab
64
fromgitlabimportcli
75
fromgitlabimportexceptionsasexc
@@ -332,7 +330,7 @@ def import_group(
332330
name:str,
333331
parent_id:Optional[str]=None,
334332
**kwargs:Any,
335-
)->Union[Dict[str,Any],requests.Response]:
333+
)->gitlab.client.HttpResponseType:
336334
"""Import a group from an archive file.
337335
338336
Args:

‎gitlab/v4/objects/merge_requests.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"""
66
fromtypingimportAny,cast,Dict,Optional,TYPE_CHECKING,Union
77

8-
importrequests
9-
108
importgitlab
119
fromgitlabimportcli
1210
fromgitlabimportexceptionsasexc
@@ -244,7 +242,7 @@ def commits(self, **kwargs: Any) -> RESTObjectList:
244242

245243
@cli.register_custom_action("ProjectMergeRequest")
246244
@exc.on_http_error(exc.GitlabListError)
247-
defchanges(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
245+
defchanges(self,**kwargs:Any)->gitlab.client.HttpResponseType:
248246
"""List the merge request changes.
249247
250248
Args:
@@ -313,7 +311,7 @@ def unapprove(self, **kwargs: Any) -> None:
313311

314312
@cli.register_custom_action("ProjectMergeRequest")
315313
@exc.on_http_error(exc.GitlabMRRebaseError)
316-
defrebase(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
314+
defrebase(self,**kwargs:Any)->gitlab.client.HttpResponseType:
317315
"""Attempt to rebase the source branch onto the target branch
318316
319317
Args:
@@ -329,7 +327,7 @@ def rebase(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
329327

330328
@cli.register_custom_action("ProjectMergeRequest")
331329
@exc.on_http_error(exc.GitlabGetError)
332-
defmerge_ref(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
330+
defmerge_ref(self,**kwargs:Any)->gitlab.client.HttpResponseType:
333331
"""Attempt to merge changes between source and target branches into
334332
`refs/merge-requests/:iid/merge`.
335333

‎gitlab/v4/objects/pipelines.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fromtypingimportAny,cast,Dict,Optional,TYPE_CHECKING,Union
22

3-
importrequests
4-
3+
importgitlab
54
fromgitlabimportcli
65
fromgitlabimportexceptionsasexc
76
fromgitlab.baseimportRESTManager,RESTObject
@@ -60,7 +59,7 @@ class ProjectPipeline(RefreshMixin, ObjectDeleteMixin, RESTObject):
6059

6160
@cli.register_custom_action("ProjectPipeline")
6261
@exc.on_http_error(exc.GitlabPipelineCancelError)
63-
defcancel(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
62+
defcancel(self,**kwargs:Any)->gitlab.client.HttpResponseType:
6463
"""Cancel the job.
6564
6665
Args:
@@ -75,7 +74,7 @@ def cancel(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
7574

7675
@cli.register_custom_action("ProjectPipeline")
7776
@exc.on_http_error(exc.GitlabPipelineRetryError)
78-
defretry(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
77+
defretry(self,**kwargs:Any)->gitlab.client.HttpResponseType:
7978
"""Retry the job.
8079
8180
Args:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp