From: W. Trevor King Date: Tue, 5 Feb 2013 16:39:43 +0000 (-0500) Subject: question: Use Question._state_attributes in __init__ and __setstate__ X-Git-Tag: v0.1~61 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a3c612a501c07996e072500b0ec24074b9a46b32;p=quizzer.git question: Use Question._state_attributes in __init__ and __setstate__ --- diff --git a/quizzer/question.py b/quizzer/question.py index f2e8ed0..7cebd30 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -14,17 +14,8 @@ class Question (object): 'dependencies', ] - def __init__(self, id=None, prompt=None, answer=None, help=None, - dependencies=None): - if id is None: - id = prompt - self.id = id - self.prompt = prompt - self.answer = answer - self.help = help - if dependencies is None: - dependencies = [] - self.dependencies = dependencies + def __init__(self, **kwargs): + self.__setstate__(kwargs) def __str__(self): return '<{} id:{!r}>'.format(type(self).__name__, self.id) @@ -42,6 +33,9 @@ class Question (object): state['id'] = state.get('prompt', None) if 'dependencies' not in state: state['dependencies'] = [] + for attr in self._state_attributes: + if attr not in state: + state[attr] = None self.__dict__.update(state) def check(self, answer):