From: W. Trevor King Date: Sat, 6 Oct 2012 16:56:22 +0000 (-0400) Subject: model:person: if not given, Person.emails and .groups default to []. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=647deb2b10e44b1d2e73312591cd0455fe6d6aa0;p=pygrader.git model:person: if not given, Person.emails and .groups default to []. This avoids problems with trying to iterate None. --- diff --git a/pygrader/model/person.py b/pygrader/model/person.py index f09d6b9..2755052 100644 --- a/pygrader/model/person.py +++ b/pygrader/model/person.py @@ -18,11 +18,15 @@ class Person (object): def __init__(self, name, emails=None, pgp_key=None, aliases=None, groups=None): self.name = name + if emails is None: + emails = [] self.emails = emails self.pgp_key = pgp_key if not aliases: aliases = [self.name] self.aliases = aliases + if groups is None: + groups = [] self.groups = groups def __str__(self): diff --git a/pygrader/storage.py b/pygrader/storage.py index 8d3d768..3b2ebf1 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -269,7 +269,7 @@ def load_person(name, data={}): Gandalf: ['g@grey.edu', 'g@greyhavens.net'] | 0x0123456789ABCDEF >>> p = load_person(name='Gandalf') >>> print('{0.name}: {0.emails} | {0.pgp_key}'.format(p)) - Gandalf: None | None + Gandalf: [] | None """ kwargs = {} emails = [x.strip() for x in data.get('emails', '').split(',')]