20
20
Any ,
21
21
Callable ,
22
22
Dict ,
23
+ Generic ,
23
24
List ,
24
25
Optional ,
26
+ Iterable ,
25
27
Tuple ,
26
28
Type ,
29
+ TypeVar ,
27
30
TYPE_CHECKING ,
28
31
Union ,
29
32
)
67
70
_RestManagerBase = object
68
71
_RestObjectBase = object
69
72
73
+ T1 = TypeVar ("T1" , bound = base .RESTObject )
74
+ T2 = TypeVar ("T2" , bound = base .RESTObject )
70
75
71
- class GetMixin (_RestManagerBase ):
76
+
77
+ class GetMixin (_RestManagerBase , Generic [T1 , T2 ]):
72
78
_computed_path : Optional [str ]
73
79
_from_parent_attrs : Dict [str , Any ]
74
- _obj_cls : Optional [ Type [base . RESTObject ] ]
80
+ _obj_cls : Type [T1 ]
75
81
_optional_get_attrs : Tuple [str , ...] = ()
76
- _parent : Optional [base . RESTObject ]
82
+ _parent : Optional [T2 ]
77
83
_parent_attrs : Dict [str , Any ]
78
84
_path : Optional [str ]
79
85
gitlab : gitlab .Gitlab
80
86
81
87
@exc .on_http_error (exc .GitlabGetError )
82
88
def get (
83
89
self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any
84
- ) -> base . RESTObject :
90
+ ) -> T1 :
85
91
"""Retrieve a single object.
86
92
87
93
Args:
@@ -113,12 +119,12 @@ def get(
113
119
return self ._obj_cls (self , server_data )
114
120
115
121
116
- class GetWithoutIdMixin (_RestManagerBase ):
122
+ class GetWithoutIdMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
117
123
_computed_path : Optional [str ]
118
124
_from_parent_attrs : Dict [str , Any ]
119
- _obj_cls : Optional [ Type [base . RESTObject ] ]
125
+ _obj_cls : Type [T1 ]
120
126
_optional_get_attrs : Tuple [str , ...] = ()
121
- _parent : Optional [base . RESTObject ]
127
+ _parent : Optional [T2 ]
122
128
_parent_attrs : Dict [str , Any ]
123
129
_path : Optional [str ]
124
130
gitlab : gitlab .Gitlab
@@ -181,18 +187,18 @@ def refresh(self, **kwargs: Any) -> None:
181
187
self ._update_attrs (server_data )
182
188
183
189
184
- class ListMixin (_RestManagerBase ):
190
+ class ListMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
185
191
_computed_path : Optional [str ]
186
192
_from_parent_attrs : Dict [str , Any ]
187
193
_list_filters : Tuple [str , ...] = ()
188
- _obj_cls : Optional [ Type [base . RESTObject ] ]
189
- _parent : Optional [base . RESTObject ]
194
+ _obj_cls : Type [T1 ]
195
+ _parent : Optional [T2 ]
190
196
_parent_attrs : Dict [str , Any ]
191
197
_path : Optional [str ]
192
198
gitlab : gitlab .Gitlab
193
199
194
200
@exc .on_http_error (exc .GitlabListError )
195
- def list (self , ** kwargs : Any ) -> Union [ base . RESTObjectList , List [ base . RESTObject ] ]:
201
+ def list (self , ** kwargs : Any ) -> Iterable [ T1 ]:
196
202
"""Retrieve a list of objects.
197
203
198
204
Args:
@@ -234,21 +240,21 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject
234
240
return base .RESTObjectList (self , self ._obj_cls , obj )
235
241
236
242
237
- class RetrieveMixin (ListMixin , GetMixin ):
243
+ class RetrieveMixin (ListMixin , GetMixin , Generic [ T1 , T2 ] ):
238
244
_computed_path : Optional [str ]
239
245
_from_parent_attrs : Dict [str , Any ]
240
- _obj_cls : Optional [ Type [base . RESTObject ] ]
241
- _parent : Optional [base . RESTObject ]
246
+ _obj_cls : Type [T1 ]
247
+ _parent : Optional [T2 ]
242
248
_parent_attrs : Dict [str , Any ]
243
249
_path : Optional [str ]
244
250
gitlab : gitlab .Gitlab
245
251
246
252
247
- class CreateMixin (_RestManagerBase ):
253
+ class CreateMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
248
254
_computed_path : Optional [str ]
249
255
_from_parent_attrs : Dict [str , Any ]
250
- _obj_cls : Optional [ Type [base . RESTObject ] ]
251
- _parent : Optional [base . RESTObject ]
256
+ _obj_cls : Type [T1 ]
257
+ _parent : Optional [T2 ]
252
258
_parent_attrs : Dict [str , Any ]
253
259
_path : Optional [str ]
254
260
gitlab : gitlab .Gitlab
@@ -287,11 +293,11 @@ def create(
287
293
return self ._obj_cls (self , server_data )
288
294
289
295
290
- class UpdateMixin (_RestManagerBase ):
296
+ class UpdateMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
291
297
_computed_path : Optional [str ]
292
298
_from_parent_attrs : Dict [str , Any ]
293
- _obj_cls : Optional [ Type [base . RESTObject ] ]
294
- _parent : Optional [base . RESTObject ]
299
+ _obj_cls : Type [T1 ]
300
+ _parent : Optional [T2 ]
295
301
_parent_attrs : Dict [str , Any ]
296
302
_path : Optional [str ]
297
303
_update_uses_post : bool = False
@@ -352,11 +358,11 @@ def update(
352
358
return result
353
359
354
360
355
- class SetMixin (_RestManagerBase ):
361
+ class SetMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
356
362
_computed_path : Optional [str ]
357
363
_from_parent_attrs : Dict [str , Any ]
358
- _obj_cls : Optional [ Type [base . RESTObject ] ]
359
- _parent : Optional [base . RESTObject ]
364
+ _obj_cls : Type [T1 ]
365
+ _parent : Optional [T2 ]
360
366
_parent_attrs : Dict [str , Any ]
361
367
_path : Optional [str ]
362
368
gitlab : gitlab .Gitlab
@@ -386,11 +392,11 @@ def set(self, key: str, value: str, **kwargs: Any) -> base.RESTObject:
386
392
return self ._obj_cls (self , server_data )
387
393
388
394
389
- class DeleteMixin (_RestManagerBase ):
395
+ class DeleteMixin (_RestManagerBase , Generic [ T1 , T2 ] ):
390
396
_computed_path : Optional [str ]
391
397
_from_parent_attrs : Dict [str , Any ]
392
- _obj_cls : Optional [ Type [base . RESTObject ] ]
393
- _parent : Optional [base . RESTObject ]
398
+ _obj_cls : Type [T1 ]
399
+ _parent : Optional [T2 ]
394
400
_parent_attrs : Dict [str , Any ]
395
401
_path : Optional [str ]
396
402
gitlab : gitlab .Gitlab
@@ -417,21 +423,21 @@ def delete(self, id: Optional[Union[str, int]] = None, **kwargs: Any) -> None:
417
423
self .gitlab .http_delete (path , ** kwargs )
418
424
419
425
420
- class CRUDMixin (GetMixin , ListMixin , CreateMixin , UpdateMixin , DeleteMixin ):
426
+ class CRUDMixin (GetMixin , ListMixin , CreateMixin , UpdateMixin , DeleteMixin , Generic [ T1 , T2 ] ):
421
427
_computed_path : Optional [str ]
422
428
_from_parent_attrs : Dict [str , Any ]
423
- _obj_cls : Optional [ Type [base . RESTObject ] ]
424
- _parent : Optional [base . RESTObject ]
429
+ _obj_cls : Type [T1 ]
430
+ _parent : Optional [T2 ]
425
431
_parent_attrs : Dict [str , Any ]
426
432
_path : Optional [str ]
427
433
gitlab : gitlab .Gitlab
428
434
429
435
430
- class NoUpdateMixin (GetMixin , ListMixin , CreateMixin , DeleteMixin ):
436
+ class NoUpdateMixin (GetMixin , ListMixin , CreateMixin , DeleteMixin , Generic [ T1 , T2 ] ):
431
437
_computed_path : Optional [str ]
432
438
_from_parent_attrs : Dict [str , Any ]
433
- _obj_cls : Optional [ Type [base . RESTObject ] ]
434
- _parent : Optional [ base . RESTObject ]
439
+ _obj_cls : Type [T1 ]
440
+ _parent : T2
435
441
_parent_attrs : Dict [str , Any ]
436
442
_path : Optional [str ]
437
443
gitlab : gitlab .Gitlab
0 commit comments