1
+ from typing import Any , cast , Dict , Optional , TYPE_CHECKING , Union
2
+
1
3
from gitlab import exceptions as exc
2
4
from gitlab .base import RequiredOptional , RESTManager , RESTObject
3
5
from gitlab .mixins import (
22
24
23
25
class GroupLabel (SubscribableMixin , SaveMixin , ObjectDeleteMixin , RESTObject ):
24
26
_id_attr = "name"
27
+ manager : "GroupLabelManager"
25
28
26
29
# Update without ID, but we need an ID to get from list.
27
30
@exc .on_http_error (exc .GitlabUpdateError )
28
- def save (self , ** kwargs ) :
31
+ def save (self , ** kwargs : Any ) -> None :
29
32
"""Saves the changes made to the object to the server.
30
33
31
34
The object is updated to match what the server returns.
@@ -56,7 +59,14 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
56
59
)
57
60
58
61
# Update without ID.
59
- def update (self , name , new_data = None , ** kwargs ):
62
+ # NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
63
+ # type error
64
+ def update ( # type: ignore
65
+ self ,
66
+ name : Optional [str ],
67
+ new_data : Optional [Dict [str , Any ]] = None ,
68
+ ** kwargs : Any
69
+ ) -> Dict [str , Any ]:
60
70
"""Update a Label on the server.
61
71
62
72
Args:
@@ -70,7 +80,9 @@ def update(self, name, new_data=None, **kwargs):
70
80
71
81
# Delete without ID.
72
82
@exc .on_http_error (exc .GitlabDeleteError )
73
- def delete (self , name , ** kwargs ):
83
+ # NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84
+ # type error
85
+ def delete (self , name : str , ** kwargs : Any ) -> None : # type: ignore
74
86
"""Delete a Label on the server.
75
87
76
88
Args:
@@ -81,17 +93,20 @@ def delete(self, name, **kwargs):
81
93
GitlabAuthenticationError: If authentication is not correct
82
94
GitlabDeleteError: If the server cannot perform the request
83
95
"""
96
+ if TYPE_CHECKING :
97
+ assert self .path is not None
84
98
self .gitlab .http_delete (self .path , query_data = {"name" : name }, ** kwargs )
85
99
86
100
87
101
class ProjectLabel (
88
102
PromoteMixin , SubscribableMixin , SaveMixin , ObjectDeleteMixin , RESTObject
89
103
):
90
104
_id_attr = "name"
105
+ manager : "ProjectLabelManager"
91
106
92
107
# Update without ID, but we need an ID to get from list.
93
108
@exc .on_http_error (exc .GitlabUpdateError )
94
- def save (self , ** kwargs ) :
109
+ def save (self , ** kwargs : Any ) -> None :
95
110
"""Saves the changes made to the object to the server.
96
111
97
112
The object is updated to match what the server returns.
@@ -123,8 +138,20 @@ class ProjectLabelManager(
123
138
required = ("name" ,), optional = ("new_name" , "color" , "description" , "priority" )
124
139
)
125
140
141
+ def get (
142
+ self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any
143
+ ) -> ProjectLabel :
144
+ return cast (ProjectLabel , super ().get (id = id , lazy = lazy , ** kwargs ))
145
+
126
146
# Update without ID.
127
- def update (self , name , new_data = None , ** kwargs ):
147
+ # NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
148
+ # type error
149
+ def update ( # type: ignore
150
+ self ,
151
+ name : Optional [str ],
152
+ new_data : Optional [Dict [str , Any ]] = None ,
153
+ ** kwargs : Any
154
+ ) -> Dict [str , Any ]:
128
155
"""Update a Label on the server.
129
156
130
157
Args:
@@ -138,7 +165,9 @@ def update(self, name, new_data=None, **kwargs):
138
165
139
166
# Delete without ID.
140
167
@exc .on_http_error (exc .GitlabDeleteError )
141
- def delete (self , name , ** kwargs ):
168
+ # NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169
+ # type error
170
+ def delete (self , name : str , ** kwargs : Any ) -> None : # type: ignore
142
171
"""Delete a Label on the server.
143
172
144
173
Args:
@@ -149,4 +178,6 @@ def delete(self, name, **kwargs):
149
178
GitlabAuthenticationError: If authentication is not correct
150
179
GitlabDeleteError: If the server cannot perform the request
151
180
"""
181
+ if TYPE_CHECKING :
182
+ assert self .path is not None
152
183
self .gitlab .http_delete (self .path , query_data = {"name" : name }, ** kwargs )
0 commit comments