remove the mutable default arguments "[]" or "{}"

remove the default arguments "[]" or "{}" when the function is defined.
ref: http://docs.python-guide.org/en/latest/writing/gotchas/

Change-Id: I93de22c6b3a48c3a0e6365756f8b6b5839844826
This commit is contained in:
Javeme 2015-12-16 16:48:51 +08:00
parent 4c649151cf
commit eb68e1f55e
5 changed files with 15 additions and 6 deletions

View File

@ -346,7 +346,7 @@ class ContribResourcePages(ResourcePages):
return 'heat.engine.plugins'
def _filter_resources(prefix=None, path=None, statuses=[]):
def _filter_resources(prefix=None, path=None, statuses=None):
def not_hidden_match(cls):
return cls.support_status.status != support.HIDDEN
@ -360,6 +360,7 @@ def _filter_resources(prefix=None, path=None, statuses=[]):
def status_match(cls):
return cls.support_status.status in statuses
statuses = statuses or []
filtered_resources = {}
for name in sorted(six.iterkeys(all_resources)):
if prefix_match(name):

View File

@ -16,8 +16,8 @@
import sqlalchemy
def clone_table(name, parent, meta, newcols=[], ignorecols=[], swapcols={},
ignorecons=[]):
def clone_table(name, parent, meta, newcols=None, ignorecols=None,
swapcols=None, ignorecons=None):
"""Helper function that clones parent table schema onto new table.
:param name: new table name
@ -30,6 +30,11 @@ def clone_table(name, parent, meta, newcols=[], ignorecols=[], swapcols={},
:return: sqlalchemy.Table instance
"""
newcols = newcols or []
ignorecols = ignorecols or []
swapcols = swapcols or {}
ignorecons = ignorecons or []
cols = [c.copy() for c in parent.columns
if c.name not in ignorecols
if c.name not in swapcols]

View File

@ -643,7 +643,7 @@ class Resource(object):
else:
self.state_set(action, self.COMPLETE)
def action_handler_task(self, action, args=[], action_prefix=None):
def action_handler_task(self, action, args=None, action_prefix=None):
"""A task to call the Resource subclass's handler methods for action.
Calls the handle_<ACTION>() method for the given action and then calls
@ -655,6 +655,7 @@ class Resource(object):
If a prefix is supplied, the handler method handle_<PREFIX>_<ACTION>()
is called instead.
"""
args = args or []
handler_action = action.lower()
check = getattr(self, 'check_%s_complete' % handler_action, None)

View File

@ -2900,7 +2900,8 @@ class ResourceHookTest(common.HeatTestCase):
class ResourceAvailabilityTest(common.HeatTestCase):
def _mock_client_plugin(self, service_types=[], is_available=True):
def _mock_client_plugin(self, service_types=None, is_available=True):
service_types = service_types or []
mock_client_plugin = mock.Mock()
mock_service_types = mock.PropertyMock(return_value=service_types)
type(mock_client_plugin).service_types = mock_service_types

View File

@ -89,7 +89,8 @@ class DummyClass(object):
class TemplatePluginFixture(fixtures.Fixture):
def __init__(self, templates={}):
def __init__(self, templates=None):
templates = templates or {}
super(TemplatePluginFixture, self).__init__()
self.templates = [extension.Extension(k, None, v, None)
for (k, v) in templates.items()]