diff options
author | Alessio Sergi <al3hex@gmail.com> | 2015-02-22 15:15:15 +0100 |
---|---|---|
committer | Alessio Sergi <al3hex@gmail.com> | 2015-02-22 15:43:07 +0100 |
commit | e2912943c527594f4f91f691714bf6408ee5d6d0 (patch) | |
tree | 65f614eed1efe22d9a7e85b2daaa9250569ec2f2 | |
parent | c7580a47ed450e9e5a4bff33cf727422474ae6f8 (diff) |
Do not use mutable objects as default argument values
Use None as a default value.
See https://stackoverflow.com/questions/101268/hidden-features-of-python#113198
for more information.
-rw-r--r-- | glances/core/glances_logs.py | 5 | ||||
-rw-r--r-- | glances/core/glances_stats.py | 8 | ||||
-rw-r--r-- | glances/plugins/glances_plugin.py | 4 |
3 files changed, 12 insertions, 5 deletions
diff --git a/glances/core/glances_logs.py b/glances/core/glances_logs.py index c795e17b..d0c41ee9 100644 --- a/glances/core/glances_logs.py +++ b/glances/core/glances_logs.py @@ -101,8 +101,7 @@ class GlancesLogs(object): return process_auto_by def add(self, item_state, item_type, item_value, - proc_list=[], proc_desc="", - peak_time=3): + proc_list=None, proc_desc="", peak_time=3): """Add a new item to the logs list. If 'item' is a 'new one', add the new item at the beginning of the logs @@ -110,6 +109,8 @@ class GlancesLogs(object): If 'item' is not a 'new one', update the existing item. If event < peak_time the the alert is not setoff """ + proc_list = proc_list or [] + # Add or update the log item_index = self.__itemexist__(item_type) if item_index < 0: diff --git a/glances/core/glances_stats.py b/glances/core/glances_stats.py index 8b92334f..a4bbab0d 100644 --- a/glances/core/glances_stats.py +++ b/glances/core/glances_stats.py @@ -155,10 +155,12 @@ class GlancesStats(object): #Â logger.debug("Update %s stats" % p) self._plugins[p].update() - def export(self, input_stats={}): + def export(self, input_stats=None): """Export all the stats. Each export module is ran in a dedicated thread.""" # threads = [] + input_stats = input_stats or {} + for e in self._exports: logger.debug("Export stats using the %s module" % e) thread = threading.Thread(target=self._exports[e].update, @@ -231,8 +233,10 @@ class GlancesStatsServer(GlancesStats): # all_stats is a dict of dicts filled by the server self.all_stats = collections.defaultdict(dict) - def update(self, input_stats={}): + def update(self, input_stats=None): """Update the stats.""" + input_stats = input_stats or {} + # Force update of all the stats GlancesStats.update(self) diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 7ff575f6..f3929892 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -161,11 +161,13 @@ class GlancesPlugin(object): self.stats = input_stats return self.stats - def set_stats_snmp(self, bulk=False, snmp_oid={}): + def set_stats_snmp(self, bulk=False, snmp_oid=None): """Update stats using SNMP. If bulk=True, use a bulk request instead of a get request. """ + snmp_oid = snmp_oid or {} + from glances.core.glances_snmp import GlancesSNMPClient # Init the SNMP request |