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

Commitd04e557

Browse files
chore: add type-hints to gitlab/v4/objects/labels.py
1 parenta91a303 commitd04e557

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

‎gitlab/v4/objects/labels.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fromtypingimportAny,cast,Dict,Optional,TYPE_CHECKING,Union
2+
13
fromgitlabimportexceptionsasexc
24
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
35
fromgitlab.mixinsimport (
@@ -22,10 +24,11 @@
2224

2325
classGroupLabel(SubscribableMixin,SaveMixin,ObjectDeleteMixin,RESTObject):
2426
_id_attr="name"
27+
manager:"GroupLabelManager"
2528

2629
# Update without ID, but we need an ID to get from list.
2730
@exc.on_http_error(exc.GitlabUpdateError)
28-
defsave(self,**kwargs):
31+
defsave(self,**kwargs:Any)->None:
2932
"""Saves the changes made to the object to the server.
3033
3134
The object is updated to match what the server returns.
@@ -56,7 +59,14 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
5659
)
5760

5861
# Update without ID.
59-
defupdate(self,name,new_data=None,**kwargs):
62+
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
63+
# type error
64+
defupdate(# type: ignore
65+
self,
66+
name:Optional[str],
67+
new_data:Optional[Dict[str,Any]]=None,
68+
**kwargs:Any
69+
)->Dict[str,Any]:
6070
"""Update a Label on the server.
6171
6272
Args:
@@ -70,7 +80,9 @@ def update(self, name, new_data=None, **kwargs):
7080

7181
# Delete without ID.
7282
@exc.on_http_error(exc.GitlabDeleteError)
73-
defdelete(self,name,**kwargs):
83+
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84+
# type error
85+
defdelete(self,name:str,**kwargs:Any)->None:# type: ignore
7486
"""Delete a Label on the server.
7587
7688
Args:
@@ -81,17 +93,20 @@ def delete(self, name, **kwargs):
8193
GitlabAuthenticationError: If authentication is not correct
8294
GitlabDeleteError: If the server cannot perform the request
8395
"""
96+
ifTYPE_CHECKING:
97+
assertself.pathisnotNone
8498
self.gitlab.http_delete(self.path,query_data={"name":name},**kwargs)
8599

86100

87101
classProjectLabel(
88102
PromoteMixin,SubscribableMixin,SaveMixin,ObjectDeleteMixin,RESTObject
89103
):
90104
_id_attr="name"
105+
manager:"ProjectLabelManager"
91106

92107
# Update without ID, but we need an ID to get from list.
93108
@exc.on_http_error(exc.GitlabUpdateError)
94-
defsave(self,**kwargs):
109+
defsave(self,**kwargs:Any)->None:
95110
"""Saves the changes made to the object to the server.
96111
97112
The object is updated to match what the server returns.
@@ -123,8 +138,20 @@ class ProjectLabelManager(
123138
required=("name",),optional=("new_name","color","description","priority")
124139
)
125140

141+
defget(
142+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
143+
)->ProjectLabel:
144+
returncast(ProjectLabel,super().get(id=id,lazy=lazy,**kwargs))
145+
126146
# Update without ID.
127-
defupdate(self,name,new_data=None,**kwargs):
147+
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
148+
# type error
149+
defupdate(# type: ignore
150+
self,
151+
name:Optional[str],
152+
new_data:Optional[Dict[str,Any]]=None,
153+
**kwargs:Any
154+
)->Dict[str,Any]:
128155
"""Update a Label on the server.
129156
130157
Args:
@@ -138,7 +165,9 @@ def update(self, name, new_data=None, **kwargs):
138165

139166
# Delete without ID.
140167
@exc.on_http_error(exc.GitlabDeleteError)
141-
defdelete(self,name,**kwargs):
168+
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169+
# type error
170+
defdelete(self,name:str,**kwargs:Any)->None:# type: ignore
142171
"""Delete a Label on the server.
143172
144173
Args:
@@ -149,4 +178,6 @@ def delete(self, name, **kwargs):
149178
GitlabAuthenticationError: If authentication is not correct
150179
GitlabDeleteError: If the server cannot perform the request
151180
"""
181+
ifTYPE_CHECKING:
182+
assertself.pathisnotNone
152183
self.gitlab.http_delete(self.path,query_data={"name":name},**kwargs)

‎pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module = [
1313
"docs.*",
1414
"docs.ext.*",
1515
"gitlab.v4.objects.files",
16-
"gitlab.v4.objects.labels",
1716
"tests.functional.*",
1817
"tests.functional.api.*",
1918
"tests.meta.*",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp