From a3c612a501c07996e072500b0ec24074b9a46b32 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 5 Feb 2013 11:39:43 -0500 Subject: [PATCH] question: Use Question._state_attributes in __init__ and __setstate__ --- quizzer/question.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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): -- 2.26.2