Skip to content

Commit 8fc8e35

Browse files
fix: remove empty dict default arguments
Signed-off-by: Frantisek Lachman <flachman@redhat.com>
1 parent edb3359 commit 8fc8e35

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

gitlab/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def http_request(
443443
self,
444444
verb,
445445
path,
446-
query_data={},
446+
query_data=None,
447447
post_data=None,
448448
streamed=False,
449449
files=None,
@@ -469,7 +469,7 @@ def http_request(
469469
Raises:
470470
GitlabHttpError: When the return code is not 2xx
471471
"""
472-
472+
query_data = query_data or {}
473473
url = self._build_url(path)
474474

475475
params = {}
@@ -564,7 +564,7 @@ def http_request(
564564
response_body=result.content,
565565
)
566566

567-
def http_get(self, path, query_data={}, streamed=False, raw=False, **kwargs):
567+
def http_get(self, path, query_data=None, streamed=False, raw=False, **kwargs):
568568
"""Make a GET request to the Gitlab server.
569569
570570
Args:
@@ -584,6 +584,7 @@ def http_get(self, path, query_data={}, streamed=False, raw=False, **kwargs):
584584
GitlabHttpError: When the return code is not 2xx
585585
GitlabParsingError: If the json data could not be parsed
586586
"""
587+
query_data = query_data or {}
587588
result = self.http_request(
588589
"get", path, query_data=query_data, streamed=streamed, **kwargs
589590
)
@@ -602,7 +603,7 @@ def http_get(self, path, query_data={}, streamed=False, raw=False, **kwargs):
602603
else:
603604
return result
604605

605-
def http_list(self, path, query_data={}, as_list=None, **kwargs):
606+
def http_list(self, path, query_data=None, as_list=None, **kwargs):
606607
"""Make a GET request to the Gitlab server for list-oriented queries.
607608
608609
Args:
@@ -623,6 +624,7 @@ def http_list(self, path, query_data={}, as_list=None, **kwargs):
623624
GitlabHttpError: When the return code is not 2xx
624625
GitlabParsingError: If the json data could not be parsed
625626
"""
627+
query_data = query_data or {}
626628

627629
# In case we want to change the default behavior at some point
628630
as_list = True if as_list is None else as_list
@@ -640,7 +642,7 @@ def http_list(self, path, query_data={}, as_list=None, **kwargs):
640642
# No pagination, generator requested
641643
return GitlabList(self, url, query_data, **kwargs)
642644

643-
def http_post(self, path, query_data={}, post_data={}, files=None, **kwargs):
645+
def http_post(self, path, query_data=None, post_data=None, files=None, **kwargs):
644646
"""Make a POST request to the Gitlab server.
645647
646648
Args:
@@ -660,6 +662,9 @@ def http_post(self, path, query_data={}, post_data={}, files=None, **kwargs):
660662
GitlabHttpError: When the return code is not 2xx
661663
GitlabParsingError: If the json data could not be parsed
662664
"""
665+
query_data = query_data or {}
666+
post_data = post_data or {}
667+
663668
result = self.http_request(
664669
"post",
665670
path,
@@ -675,7 +680,7 @@ def http_post(self, path, query_data={}, post_data={}, files=None, **kwargs):
675680
raise GitlabParsingError(error_message="Failed to parse the server message")
676681
return result
677682

678-
def http_put(self, path, query_data={}, post_data={}, files=None, **kwargs):
683+
def http_put(self, path, query_data=None, post_data=None, files=None, **kwargs):
679684
"""Make a PUT request to the Gitlab server.
680685
681686
Args:
@@ -694,6 +699,9 @@ def http_put(self, path, query_data={}, post_data={}, files=None, **kwargs):
694699
GitlabHttpError: When the return code is not 2xx
695700
GitlabParsingError: If the json data could not be parsed
696701
"""
702+
query_data = query_data or {}
703+
post_data = post_data or {}
704+
697705
result = self.http_request(
698706
"put",
699707
path,
@@ -755,7 +763,8 @@ def __init__(self, gl, url, query_data, get_next=True, **kwargs):
755763
self._query(url, query_data, **kwargs)
756764
self._get_next = get_next
757765

758-
def _query(self, url, query_data={}, **kwargs):
766+
def _query(self, url, query_data=None, **kwargs):
767+
query_data = query_data or {}
759768
result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
760769
try:
761770
self._next_url = result.links["next"]["url"]

gitlab/mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _get_update_method(self):
240240
return http_method
241241

242242
@exc.on_http_error(exc.GitlabUpdateError)
243-
def update(self, id=None, new_data={}, **kwargs):
243+
def update(self, id=None, new_data=None, **kwargs):
244244
"""Update an object on the server.
245245
246246
Args:
@@ -255,6 +255,7 @@ def update(self, id=None, new_data={}, **kwargs):
255255
GitlabAuthenticationError: If authentication is not correct
256256
GitlabUpdateError: If the server cannot perform the request
257257
"""
258+
new_data = new_data or {}
258259

259260
if id is None:
260261
path = self.path

gitlab/v4/objects.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
530530
)
531531

532532
@exc.on_http_error(exc.GitlabUpdateError)
533-
def update(self, id=None, new_data={}, **kwargs):
533+
def update(self, id=None, new_data=None, **kwargs):
534534
"""Update an object on the server.
535535
536536
Args:
@@ -545,7 +545,7 @@ def update(self, id=None, new_data={}, **kwargs):
545545
GitlabAuthenticationError: If authentication is not correct
546546
GitlabUpdateError: If the server cannot perform the request
547547
"""
548-
548+
new_data = new_data or {}
549549
data = new_data.copy()
550550
if "domain_whitelist" in data and data["domain_whitelist"] is None:
551551
data.pop("domain_whitelist")
@@ -865,13 +865,14 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
865865
_update_attrs = (("name",), ("new_name", "color", "description", "priority"))
866866

867867
# Update without ID.
868-
def update(self, name, new_data={}, **kwargs):
868+
def update(self, name, new_data=None, **kwargs):
869869
"""Update a Label on the server.
870870
871871
Args:
872872
name: The name of the label
873873
**kwargs: Extra options to send to the server (e.g. sudo)
874874
"""
875+
new_data = new_data or {}
875876
new_data["name"] = name
876877
super().update(id=None, new_data=new_data, **kwargs)
877878

@@ -2994,13 +2995,14 @@ class ProjectLabelManager(
29942995
_update_attrs = (("name",), ("new_name", "color", "description", "priority"))
29952996

29962997
# Update without ID.
2997-
def update(self, name, new_data={}, **kwargs):
2998+
def update(self, name, new_data=None, **kwargs):
29982999
"""Update a Label on the server.
29993000
30003001
Args:
30013002
name: The name of the label
30023003
**kwargs: Extra options to send to the server (e.g. sudo)
30033004
"""
3005+
new_data = new_data or {}
30043006
new_data["name"] = name
30053007
super().update(id=None, new_data=new_data, **kwargs)
30063008

@@ -3130,7 +3132,7 @@ def create(self, data, **kwargs):
31303132
return self._obj_cls(self, server_data)
31313133

31323134
@exc.on_http_error(exc.GitlabUpdateError)
3133-
def update(self, file_path, new_data={}, **kwargs):
3135+
def update(self, file_path, new_data=None, **kwargs):
31343136
"""Update an object on the server.
31353137
31363138
Args:
@@ -3145,7 +3147,7 @@ def update(self, file_path, new_data={}, **kwargs):
31453147
GitlabAuthenticationError: If authentication is not correct
31463148
GitlabUpdateError: If the server cannot perform the request
31473149
"""
3148-
3150+
new_data = new_data or {}
31493151
data = new_data.copy()
31503152
file_path = file_path.replace("/", "%2F")
31513153
data["file_path"] = file_path
@@ -3632,7 +3634,7 @@ def get(self, id, **kwargs):
36323634
obj.id = id
36333635
return obj
36343636

3635-
def update(self, id=None, new_data={}, **kwargs):
3637+
def update(self, id=None, new_data=None, **kwargs):
36363638
"""Update an object on the server.
36373639
36383640
Args:
@@ -3647,6 +3649,7 @@ def update(self, id=None, new_data={}, **kwargs):
36473649
GitlabAuthenticationError: If authentication is not correct
36483650
GitlabUpdateError: If the server cannot perform the request
36493651
"""
3652+
new_data = new_data or {}
36503653
super(ProjectServiceManager, self).update(id, new_data, **kwargs)
36513654
self.id = id
36523655

@@ -4182,7 +4185,7 @@ def unshare(self, group_id, **kwargs):
41824185
# variables not supported in CLI
41834186
@cli.register_custom_action("Project", ("ref", "token"))
41844187
@exc.on_http_error(exc.GitlabCreateError)
4185-
def trigger_pipeline(self, ref, token, variables={}, **kwargs):
4188+
def trigger_pipeline(self, ref, token, variables=None, **kwargs):
41864189
"""Trigger a CI build.
41874190
41884191
See https://gitlab.com/help/ci/triggers/README.md#trigger-a-build
@@ -4197,6 +4200,7 @@ def trigger_pipeline(self, ref, token, variables={}, **kwargs):
41974200
GitlabAuthenticationError: If authentication is not correct
41984201
GitlabCreateError: If the server failed to perform the request
41994202
"""
4203+
variables = variables or {}
42004204
path = "/projects/%s/trigger/pipeline" % self.get_id()
42014205
post_data = {"ref": ref, "token": token, "variables": variables}
42024206
attrs = self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)

0 commit comments

Comments
 (0)