summaryrefslogtreecommitdiff
path: root/alot/account.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/account.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/account.py')
-rw-r--r--alot/account.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/alot/account.py b/alot/account.py
index 6687f13c..2b122e78 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -52,10 +52,17 @@ class Account(object):
def __init__(self, address=None, aliases=None, alias_regexp=None,
realname=None, gpg_key=None, signature=None,
signature_filename=None, signature_as_attachment=False,
- sent_box=None, sent_tags=['sent'], draft_box=None,
- draft_tags=['draft'], abook=None, sign_by_default=False,
+ sent_box=None, sent_tags=None, draft_box=None,
+ draft_tags=None, abook=None, sign_by_default=False,
encrypt_by_default=u"none",
**rest):
+ sent_tags = sent_tags or []
+ if 'sent' not in sent_tags:
+ sent_tags.append('sent')
+ draft_tags = draft_tags or []
+ if 'draft' not in draft_tags:
+ draft_tags.append('draft')
+
self.address = address
self.aliases = aliases
self.alias_regexp = alias_regexp