From d5ba008b859e21513ba109be180da194639622ac Mon Sep 17 00:00:00 2001 From: lindsay stevens Date: Fri, 10 Jan 2025 04:28:31 +1100 Subject: [PATCH] chg: remove unnecessary re-validation of question type - type is checked during __init__, and it shouldn't change after that --- pyxform/question.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/pyxform/question.py b/pyxform/question.py index 7a877ecd..a5ceb9f2 100644 --- a/pyxform/question.py +++ b/pyxform/question.py @@ -110,8 +110,7 @@ def __init__(self, fields: tuple[str, ...] | None = None, **kwargs): qtd = kwargs.pop("question_type_dictionary", QUESTION_TYPE_DICT) type_arg = kwargs.get("type") - default_type = qtd.get(type_arg) - if default_type is None: + if type_arg not in qtd: raise PyXFormError(f"Unknown question type '{type_arg}'.") # Keeping original qtd_kwargs is only needed if output of QTD data is not @@ -139,14 +138,6 @@ def __init__(self, fields: tuple[str, ...] | None = None, **kwargs): fields = chain(QUESTION_EXTRA_FIELDS, fields) super().__init__(fields=fields, **kwargs) - def validate(self): - SurveyElement.validate(self) - - # make sure that the type of this question exists in the - # question type dictionary. - if self.type not in QUESTION_TYPE_DICT: - raise PyXFormError(f"Unknown question type '{self.type}'.") - def xml_instance(self, survey: "Survey", **kwargs): if self.default and not default_is_dynamic(self.default, self.type): result = node(self.name, str(self.default))