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

Commit472b300

Browse files
authored
Merge pull request#1680 from python-gitlab/jlvillal/mypy_small_files_1
chore: enforce type-hints on most files in gitlab/v4/objects/
2 parents9a2f54c +7828ba2 commit472b300

22 files changed

+232
-58
lines changed

‎gitlab/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ def _check_redirects(self, result: requests.Response) -> None:
495495
def_prepare_send_data(
496496
self,
497497
files:Optional[Dict[str,Any]]=None,
498-
post_data:Optional[Dict[str,Any]]=None,
498+
post_data:Optional[Union[Dict[str,Any],bytes]]=None,
499499
raw:bool=False,
500500
)->Tuple[
501-
Optional[Dict[str,Any]],
501+
Optional[Union[Dict[str,Any],bytes]],
502502
Optional[Union[Dict[str,Any],MultipartEncoder]],
503503
str,
504504
]:
@@ -508,6 +508,8 @@ def _prepare_send_data(
508508
else:
509509
# booleans does not exists for data (neither for MultipartEncoder):
510510
# cast to string int to avoid: 'bool' object has no attribute 'encode'
511+
ifTYPE_CHECKING:
512+
assertisinstance(post_data,dict)
511513
fork,vinpost_data.items():
512514
ifisinstance(v,bool):
513515
post_data[k]=str(int(v))
@@ -527,7 +529,7 @@ def http_request(
527529
verb:str,
528530
path:str,
529531
query_data:Optional[Dict[str,Any]]=None,
530-
post_data:Optional[Dict[str,Any]]=None,
532+
post_data:Optional[Union[Dict[str,Any],bytes]]=None,
531533
raw:bool=False,
532534
streamed:bool=False,
533535
files:Optional[Dict[str,Any]]=None,
@@ -544,7 +546,7 @@ def http_request(
544546
path (str): Path or full URL to query ('/projects' or
545547
'http://whatever/v4/api/projecs')
546548
query_data (dict): Data to send as query parameters
547-
post_data (dict): Data to send in the body (will be converted to
549+
post_data (dict|bytes): Data to send in the body (will be converted to
548550
json by default)
549551
raw (bool): If True, do not convert post_data to json
550552
streamed (bool): Whether the data should be streamed
@@ -800,7 +802,7 @@ def http_put(
800802
self,
801803
path:str,
802804
query_data:Optional[Dict[str,Any]]=None,
803-
post_data:Optional[Dict[str,Any]]=None,
805+
post_data:Optional[Union[Dict[str,Any],bytes]]=None,
804806
raw:bool=False,
805807
files:Optional[Dict[str,Any]]=None,
806808
**kwargs:Any,
@@ -811,7 +813,7 @@ def http_put(
811813
path (str): Path or full URL to query ('/projects' or
812814
'http://whatever/v4/api/projecs')
813815
query_data (dict): Data to send as query parameters
814-
post_data (dict): Data to send in the body (will be converted to
816+
post_data (dict|bytes): Data to send in the body (will be converted to
815817
json by default)
816818
raw (bool): If True, do not convert post_data to json
817819
files (dict): The files to send to the server

‎gitlab/v4/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def do_project_export_download(self) -> None:
103103
ifTYPE_CHECKING:
104104
assertexport_statusisnotNone
105105
data=export_status.download()
106+
ifTYPE_CHECKING:
107+
assertdataisnotNone
106108
sys.stdout.buffer.write(data)
107109

108110
exceptExceptionase:

‎gitlab/v4/objects/appearance.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Dict,Optional,Union
2+
13
fromgitlabimportexceptionsasexc
24
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
35
fromgitlab.mixinsimportGetWithoutIdMixin,SaveMixin,UpdateMixin
@@ -32,7 +34,12 @@ class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
3234
)
3335

3436
@exc.on_http_error(exc.GitlabUpdateError)
35-
defupdate(self,id=None,new_data=None,**kwargs):
37+
defupdate(
38+
self,
39+
id:Optional[Union[str,int]]=None,
40+
new_data:Dict[str,Any]=None,
41+
**kwargs:Any
42+
)->Dict[str,Any]:
3643
"""Update an object on the server.
3744
3845
Args:
@@ -49,4 +56,9 @@ def update(self, id=None, new_data=None, **kwargs):
4956
"""
5057
new_data=new_dataor {}
5158
data=new_data.copy()
52-
super(ApplicationAppearanceManager,self).update(id,data,**kwargs)
59+
returnsuper(ApplicationAppearanceManager,self).update(id,data,**kwargs)
60+
61+
defget(
62+
self,id:Optional[Union[int,str]]=None,**kwargs:Any
63+
)->Optional[ApplicationAppearance]:
64+
returncast(ApplicationAppearance,super().get(id=id,**kwargs))

‎gitlab/v4/objects/badges.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Union
2+
13
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
24
fromgitlab.mixinsimportBadgeRenderMixin,CRUDMixin,ObjectDeleteMixin,SaveMixin
35

@@ -31,3 +33,8 @@ class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
3133
_from_parent_attrs= {"project_id":"id"}
3234
_create_attrs=RequiredOptional(required=("link_url","image_url"))
3335
_update_attrs=RequiredOptional(optional=("link_url","image_url"))
36+
37+
defget(
38+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
39+
)->ProjectBadge:
40+
returncast(ProjectBadge,super().get(id=id,lazy=lazy,**kwargs))

‎gitlab/v4/objects/boards.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Union
2+
13
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
24
fromgitlab.mixinsimportCRUDMixin,ObjectDeleteMixin,SaveMixin
35

@@ -24,6 +26,11 @@ class GroupBoardListManager(CRUDMixin, RESTManager):
2426
_create_attrs=RequiredOptional(required=("label_id",))
2527
_update_attrs=RequiredOptional(required=("position",))
2628

29+
defget(
30+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
31+
)->GroupBoardList:
32+
returncast(GroupBoardList,super().get(id=id,lazy=lazy,**kwargs))
33+
2734

2835
classGroupBoard(SaveMixin,ObjectDeleteMixin,RESTObject):
2936
lists:GroupBoardListManager
@@ -35,6 +42,9 @@ class GroupBoardManager(CRUDMixin, RESTManager):
3542
_from_parent_attrs= {"group_id":"id"}
3643
_create_attrs=RequiredOptional(required=("name",))
3744

45+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->GroupBoard:
46+
returncast(GroupBoard,super().get(id=id,lazy=lazy,**kwargs))
47+
3848

3949
classProjectBoardList(SaveMixin,ObjectDeleteMixin,RESTObject):
4050
pass
@@ -47,6 +57,11 @@ class ProjectBoardListManager(CRUDMixin, RESTManager):
4757
_create_attrs=RequiredOptional(required=("label_id",))
4858
_update_attrs=RequiredOptional(required=("position",))
4959

60+
defget(
61+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
62+
)->ProjectBoardList:
63+
returncast(ProjectBoardList,super().get(id=id,lazy=lazy,**kwargs))
64+
5065

5166
classProjectBoard(SaveMixin,ObjectDeleteMixin,RESTObject):
5267
lists:ProjectBoardListManager
@@ -57,3 +72,8 @@ class ProjectBoardManager(CRUDMixin, RESTManager):
5772
_obj_cls=ProjectBoard
5873
_from_parent_attrs= {"project_id":"id"}
5974
_create_attrs=RequiredOptional(required=("name",))
75+
76+
defget(
77+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
78+
)->ProjectBoard:
79+
returncast(ProjectBoard,super().get(id=id,lazy=lazy,**kwargs))

‎gitlab/v4/objects/clusters.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Dict,Optional
2+
13
fromgitlabimportexceptionsasexc
24
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
35
fromgitlab.mixinsimportCreateMixin,CRUDMixin,ObjectDeleteMixin,SaveMixin
@@ -33,7 +35,9 @@ class GroupClusterManager(CRUDMixin, RESTManager):
3335
)
3436

3537
@exc.on_http_error(exc.GitlabStopError)
36-
defcreate(self,data,**kwargs):
38+
defcreate(
39+
self,data:Optional[Dict[str,Any]]=None,**kwargs:Any
40+
)->GroupCluster:
3741
"""Create a new object.
3842
3943
Args:
@@ -51,7 +55,7 @@ def create(self, data, **kwargs):
5155
the data sent by the server
5256
"""
5357
path=f"{self.path}/user"
54-
returnCreateMixin.create(self,data,path=path,**kwargs)
58+
returncast(GroupCluster,CreateMixin.create(self,data,path=path,**kwargs))
5559

5660

5761
classProjectCluster(SaveMixin,ObjectDeleteMixin,RESTObject):
@@ -77,7 +81,9 @@ class ProjectClusterManager(CRUDMixin, RESTManager):
7781
)
7882

7983
@exc.on_http_error(exc.GitlabStopError)
80-
defcreate(self,data,**kwargs):
84+
defcreate(
85+
self,data:Optional[Dict[str,Any]]=None,**kwargs:Any
86+
)->ProjectCluster:
8187
"""Create a new object.
8288
8389
Args:
@@ -95,4 +101,4 @@ def create(self, data, **kwargs):
95101
the data sent by the server
96102
"""
97103
path=f"{self.path}/user"
98-
returnCreateMixin.create(self,data,path=path,**kwargs)
104+
returncast(ProjectCluster,CreateMixin.create(self,data,path=path,**kwargs))

‎gitlab/v4/objects/container_registry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,TYPE_CHECKING
2+
13
fromgitlabimportcli
24
fromgitlabimportexceptionsasexc
35
fromgitlab.baseimportRESTManager,RESTObject
@@ -36,7 +38,7 @@ class ProjectRegistryTagManager(DeleteMixin, RetrieveMixin, RESTManager):
3638
optional=("keep_n","name_regex_keep","older_than"),
3739
)
3840
@exc.on_http_error(exc.GitlabDeleteError)
39-
defdelete_in_bulk(self,name_regex_delete,**kwargs):
41+
defdelete_in_bulk(self,name_regex_delete:str,**kwargs:Any)->None:
4042
"""Delete Tag in bulk
4143
4244
Args:
@@ -55,4 +57,6 @@ def delete_in_bulk(self, name_regex_delete, **kwargs):
5557
valid_attrs= ["keep_n","name_regex_keep","older_than"]
5658
data= {"name_regex_delete":name_regex_delete}
5759
data.update({k:vfork,vinkwargs.items()ifkinvalid_attrs})
60+
ifTYPE_CHECKING:
61+
assertself.pathisnotNone
5862
self.gitlab.http_delete(self.path,query_data=data,**kwargs)

‎gitlab/v4/objects/deploy_keys.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fromtypingimportAny,cast,Dict,Union
2+
3+
importrequests
4+
15
fromgitlabimportcli
26
fromgitlabimportexceptionsasexc
37
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
@@ -33,7 +37,9 @@ class ProjectKeyManager(CRUDMixin, RESTManager):
3337

3438
@cli.register_custom_action("ProjectKeyManager", ("key_id",))
3539
@exc.on_http_error(exc.GitlabProjectDeployKeyError)
36-
defenable(self,key_id,**kwargs):
40+
defenable(
41+
self,key_id:int,**kwargs:Any
42+
)->Union[Dict[str,Any],requests.Response]:
3743
"""Enable a deploy key for a project.
3844
3945
Args:
@@ -43,6 +49,12 @@ def enable(self, key_id, **kwargs):
4349
Raises:
4450
GitlabAuthenticationError: If authentication is not correct
4551
GitlabProjectDeployKeyError: If the key could not be enabled
52+
53+
Returns:
54+
A dict of the result.
4655
"""
4756
path=f"{self.path}/{key_id}/enable"
48-
self.gitlab.http_post(path,**kwargs)
57+
returnself.gitlab.http_post(path,**kwargs)
58+
59+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->ProjectKey:
60+
returncast(ProjectKey,super().get(id=id,lazy=lazy,**kwargs))

‎gitlab/v4/objects/environments.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fromtypingimportAny,Dict,Union
2+
3+
importrequests
4+
15
fromgitlabimportcli
26
fromgitlabimportexceptionsasexc
37
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
@@ -19,7 +23,7 @@
1923
classProjectEnvironment(SaveMixin,ObjectDeleteMixin,RESTObject):
2024
@cli.register_custom_action("ProjectEnvironment")
2125
@exc.on_http_error(exc.GitlabStopError)
22-
defstop(self,**kwargs):
26+
defstop(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
2327
"""Stop the environment.
2428
2529
Args:
@@ -28,9 +32,12 @@ def stop(self, **kwargs):
2832
Raises:
2933
GitlabAuthenticationError: If authentication is not correct
3034
GitlabStopError: If the operation failed
35+
36+
Returns:
37+
A dict of the result.
3138
"""
3239
path=f"{self.manager.path}/{self.get_id()}/stop"
33-
self.manager.gitlab.http_post(path,**kwargs)
40+
returnself.manager.gitlab.http_post(path,**kwargs)
3441

3542

3643
classProjectEnvironmentManager(

‎gitlab/v4/objects/export_import.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Optional,Union
2+
13
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
24
fromgitlab.mixinsimportCreateMixin,DownloadMixin,GetWithoutIdMixin,RefreshMixin
35

@@ -22,6 +24,11 @@ class GroupExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
2224
_obj_cls=GroupExport
2325
_from_parent_attrs= {"group_id":"id"}
2426

27+
defget(
28+
self,id:Optional[Union[int,str]]=None,**kwargs:Any
29+
)->Optional[GroupExport]:
30+
returncast(GroupExport,super().get(id=id,**kwargs))
31+
2532

2633
classGroupImport(RESTObject):
2734
_id_attr=None
@@ -32,6 +39,11 @@ class GroupImportManager(GetWithoutIdMixin, RESTManager):
3239
_obj_cls=GroupImport
3340
_from_parent_attrs= {"group_id":"id"}
3441

42+
defget(
43+
self,id:Optional[Union[int,str]]=None,**kwargs:Any
44+
)->Optional[GroupImport]:
45+
returncast(GroupImport,super().get(id=id,**kwargs))
46+
3547

3648
classProjectExport(DownloadMixin,RefreshMixin,RESTObject):
3749
_id_attr=None
@@ -43,6 +55,11 @@ class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
4355
_from_parent_attrs= {"project_id":"id"}
4456
_create_attrs=RequiredOptional(optional=("description",))
4557

58+
defget(
59+
self,id:Optional[Union[int,str]]=None,**kwargs:Any
60+
)->Optional[ProjectExport]:
61+
returncast(ProjectExport,super().get(id=id,**kwargs))
62+
4663

4764
classProjectImport(RefreshMixin,RESTObject):
4865
_id_attr=None
@@ -52,3 +69,8 @@ class ProjectImportManager(GetWithoutIdMixin, RESTManager):
5269
_path="/projects/%(project_id)s/import"
5370
_obj_cls=ProjectImport
5471
_from_parent_attrs= {"project_id":"id"}
72+
73+
defget(
74+
self,id:Optional[Union[int,str]]=None,**kwargs:Any
75+
)->Optional[ProjectImport]:
76+
returncast(ProjectImport,super().get(id=id,**kwargs))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp