summaryrefslogtreecommitdiff
path: root/alot/db/manager.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2016-12-13 11:53:47 -0800
committerDylan Baker <dylan@pnwbakers.com>2016-12-13 12:34:15 -0800
commit02431efd92060ea5d1f64bfc700ae9b1e5f4907d (patch)
tree5fc98c8c4011bc84c2c87cec26eafd5f3bfbfefe /alot/db/manager.py
parent42504da6791fb12527c708759715b7a79d5a1ddb (diff)
Replace mutable keyword arguments
There are a number of cases of mutable keyword arguments (list and dict in this case). Mutable keyword arguments are rather dangerous, since any mutation of the default value is persistent, which will inevitably lead to bugs. For example, imagine this code: def func(def=[]): def.append('foo') return def >>> func() ['foo'] >>> func() ['foo', 'foo'] This is almost certainly not what was intended. This code generally uses the idiom of setting the default value to None, and then assigning with or `value = value or []` which will replace value with the empty list (or dict) when value is falsey, like None or another empty list.
Diffstat (limited to 'alot/db/manager.py')
-rw-r--r--alot/db/manager.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py
index 3e84a6b1..a1c0b8ed 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -398,7 +398,7 @@ class DBManager(object):
db = Database(path=self.path, mode=mode)
return db.create_query(querystring)
- def add_message(self, path, tags=[], afterwards=None):
+ def add_message(self, path, tags=None, afterwards=None):
"""
Adds a file to the notmuch index.
@@ -409,6 +409,8 @@ class DBManager(object):
:param afterwards: callback to trigger after adding
:type afterwards: callable or None
"""
+ tags = tags or []
+
if self.ro:
raise DatabaseROError()
if not is_subdir_of(path, self.path):