3333import gitlab
3434from gitlab import base , cli
3535from gitlab import exceptions as exc
36- from gitlab import types as g_types
3736from gitlab import utils
3837
3938__all__ = [
@@ -214,8 +213,8 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject
214213 GitlabListError: If the server cannot perform the request
215214 """
216215
217- # Duplicate data to avoid messing with what the user sent us
218- data = kwargs . copy ()
216+ data , _ = utils . _transform_types ( kwargs , self . _types , transform_files = False )
217+
219218 if self .gitlab .per_page :
220219 data .setdefault ("per_page" , self .gitlab .per_page )
221220
@@ -226,13 +225,6 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject
226225 if self .gitlab .order_by :
227226 data .setdefault ("order_by" , self .gitlab .order_by )
228227
229- # We get the attributes that need some special transformation
230- if self ._types :
231- for attr_name , type_cls in self ._types .items ():
232- if attr_name in data .keys ():
233- type_obj = type_cls (data [attr_name ])
234- data [attr_name ] = type_obj .get_for_api ()
235-
236228 # Allow to overwrite the path, handy for custom listings
237229 path = data .pop ("path" , self .path )
238230
@@ -298,23 +290,7 @@ def create(
298290 data = {}
299291
300292 self ._check_missing_create_attrs (data )
301- files = {}
302-
303- # We get the attributes that need some special transformation
304- if self ._types :
305- # Duplicate data to avoid messing with what the user sent us
306- data = data .copy ()
307- for attr_name , type_cls in self ._types .items ():
308- if attr_name in data .keys ():
309- type_obj = type_cls (data [attr_name ])
310-
311- # if the type if FileAttribute we need to pass the data as
312- # file
313- if isinstance (type_obj , g_types .FileAttribute ):
314- k = type_obj .get_file_name (attr_name )
315- files [attr_name ] = (k , data .pop (attr_name ))
316- else :
317- data [attr_name ] = type_obj .get_for_api ()
293+ data , files = utils ._transform_types (data , self ._types )
318294
319295 # Handle specific URL for creation
320296 path = kwargs .pop ("path" , self .path )
@@ -394,23 +370,7 @@ def update(
394370 path = f"{ self .path } /{ utils .EncodedId (id )} "
395371
396372 self ._check_missing_update_attrs (new_data )
397- files = {}
398-
399- # We get the attributes that need some special transformation
400- if self ._types :
401- # Duplicate data to avoid messing with what the user sent us
402- new_data = new_data .copy ()
403- for attr_name , type_cls in self ._types .items ():
404- if attr_name in new_data .keys ():
405- type_obj = type_cls (new_data [attr_name ])
406-
407- # if the type if FileAttribute we need to pass the data as
408- # file
409- if isinstance (type_obj , g_types .FileAttribute ):
410- k = type_obj .get_file_name (attr_name )
411- files [attr_name ] = (k , new_data .pop (attr_name ))
412- else :
413- new_data [attr_name ] = type_obj .get_for_api ()
373+ new_data , files = utils ._transform_types (new_data , self ._types )
414374
415375 http_method = self ._get_update_method ()
416376 result = http_method (path , post_data = new_data , files = files , ** kwargs )
0 commit comments