summaryrefslogtreecommitdiff
path: root/openstackclient/common/utils.py
diff options
context:
space:
mode:
authorting.wang <ting.wang@easystack.cn>2016-02-20 16:35:11 +0800
committerting.wang <ting.wang@easystack.cn>2016-02-20 16:35:11 +0800
commitdc5a8faddd2f7f7afb29751b7d00eb6b5474857f (patch)
tree60d2bef7055f97e32317ca83fe5132e0953ddfa7 /openstackclient/common/utils.py
parentab6ba385a2c292a7a906390ad911db8c59811a07 (diff)
downloadpython-openstackclient-dc5a8faddd2f7f7afb29751b7d00eb6b5474857f.tar.gz
Fix Mutable default argument
Python’s default arguments are evaluated once when the function is defined, not each time the function is called. This means that if you use a mutable default argument (like list and dict) and mutate it, you will and have mutated that object for all future calls to the function as well. more details about this wrong usage here: http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments Change-Id: If187f16bfb305ac4fe6e4177e498a06c49c3f946
Diffstat (limited to 'openstackclient/common/utils.py')
-rw-r--r--openstackclient/common/utils.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 4142f830..840da402 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -163,7 +163,7 @@ def get_field(item, field):
raise exceptions.CommandError(msg)
-def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
+def get_item_properties(item, fields, mixed_case_fields=None, formatters=None):
"""Return a tuple containing the item properties.
:param item: a single item resource (e.g. Server, Project, etc)
@@ -172,6 +172,11 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
:param formatters: dictionary mapping field names to callables
to format the values
"""
+ if mixed_case_fields is None:
+ mixed_case_fields = []
+ if formatters is None:
+ formatters = {}
+
row = []
for field in fields:
@@ -187,7 +192,7 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
return tuple(row)
-def get_dict_properties(item, fields, mixed_case_fields=[], formatters={}):
+def get_dict_properties(item, fields, mixed_case_fields=None, formatters=None):
"""Return a tuple containing the item properties.
:param item: a single dict resource
@@ -196,6 +201,11 @@ def get_dict_properties(item, fields, mixed_case_fields=[], formatters={}):
:param formatters: dictionary mapping field names to callables
to format the values
"""
+ if mixed_case_fields is None:
+ mixed_case_fields = []
+ if formatters is None:
+ formatters = {}
+
row = []
for field in fields: