model:person: if not given, Person.emails and .groups default to [].
authorW. Trevor King <wking@tremily.us>
Sat, 6 Oct 2012 16:56:22 +0000 (12:56 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 6 Oct 2012 16:56:22 +0000 (12:56 -0400)
This avoids problems with trying to iterate None.

pygrader/model/person.py
pygrader/storage.py

index f09d6b95b686de02c62041777d2a27ee6a3ebb36..27550526cedd0a47e787e8b7c0a8bc3b6d0e804a 100644 (file)
@@ -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):
index 8d3d7683d61a6c596a332140caa9f56bd5bd32ae..3b2ebf1284900aad79ad13dadf9ae90b905e32b1 100644 (file)
@@ -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(',')]