From 91e098e0ea46a7674f9d0fb6e4734675c658f444 Mon Sep 17 00:00:00 2001 From: jiansong Date: Fri, 7 Oct 2016 19:23:48 -0700 Subject: [PATCH] Avoid use xx=[] for parameter in function Use xx = [] for the parameter for function, this parameter will only be initialized at the first call, this is should be avoided. Better choice is to set the initial value to None, then the initialization time use xx= xx or [] more information:http://effbot.org/zone/default-values.htm Change-Id: Icbade7dd4c7d231ae65fd4f8de673b484bab721c --- troveclient/common.py | 4 +++- troveclient/compat/common.py | 6 +++--- troveclient/v1/management.py | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/troveclient/common.py b/troveclient/common.py index 8c1efb31..dc7a94a3 100644 --- a/troveclient/common.py +++ b/troveclient/common.py @@ -42,7 +42,9 @@ def quote_user_host(user, host): class Paginated(list): - def __init__(self, items=[], next_marker=None, links=[]): + def __init__(self, items=None, next_marker=None, links=None): + items = items or [] + links = links or [] super(Paginated, self).__init__(items) self.next = next_marker self.links = links diff --git a/troveclient/compat/common.py b/troveclient/compat/common.py index 152ea775..ec7854f6 100644 --- a/troveclient/compat/common.py +++ b/troveclient/compat/common.py @@ -399,10 +399,10 @@ class Paginated(object): next property you can use to get the next page of data. """ - def __init__(self, items=[], next_marker=None, links=[]): - self.items = items + def __init__(self, items=None, next_marker=None, links=None): + self.items = items or [] self.next = next_marker - self.links = links + self.links = links or [] def __len__(self): return len(self.items) diff --git a/troveclient/v1/management.py b/troveclient/v1/management.py index 4b572051..01ebf0a7 100644 --- a/troveclient/v1/management.py +++ b/troveclient/v1/management.py @@ -272,7 +272,8 @@ class MgmtDatastoreVersions(base.ManagerWithFind): "version") def create(self, name, datastore_name, datastore_manager, image, - packages=[], active='true', default='false'): + packages=None, active='true', default='false'): + packages = packages or [] """Create a new datastore version.""" body = {"version": { "name": name, @@ -287,7 +288,8 @@ class MgmtDatastoreVersions(base.ManagerWithFind): return self._create("/mgmt/datastore-versions", body, None, True) def edit(self, datastore_version_id, datastore_manager=None, image=None, - packages=[], active=None, default=None): + packages=None, active=None, default=None): + packages = packages or [] """Update a datastore-version.""" body = {} if datastore_manager is not None: