From 262cd6deeff6be0346d0d48e260c286c1b426ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 11 Nov 2022 19:24:28 +0100 Subject: [PATCH] MAINT: doc strings and move of dict merge --- src/caoscrawler/converters.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/caoscrawler/converters.py b/src/caoscrawler/converters.py index 22dc27a9..84928d62 100644 --- a/src/caoscrawler/converters.py +++ b/src/caoscrawler/converters.py @@ -644,8 +644,17 @@ class _AbstractDictElementConverter(Converter): values.update(m2.groupdict()) return values - def _typecheck(self, element: StructureElement, default: Dict, definition: Dict): - allowed_matches = self._merge_match_definition_with_default(default, definition) + def _typecheck(self, element: StructureElement, allowed_matches: Dict): + """ + returns whether the type of StructureElement is accepted. + + Parameters: + element: StructureElement, the element that is checked + allowed_matches: Dict, a dictionary that defines what types are allowed. It must have the + keys 'accept_text', 'accept_bool', 'accept_int', and 'accept_float'. + + returns: whether or not the converter allows the type of element + """ if (bool(allowed_matches["accept_text"]) and isinstance(element, DictTextElement)): return True elif (bool(allowed_matches["accept_bool"]) and isinstance(element, DictBooleanElement)): @@ -658,6 +667,11 @@ class _AbstractDictElementConverter(Converter): return False def _merge_match_definition_with_default(self, default: Dict, definition: Dict): + """ + returns a dict with the same keys as default dict but with updated values from definition + where it has the same keys + """ + result = {} for key in default: if key in definition: @@ -667,7 +681,9 @@ class _AbstractDictElementConverter(Converter): return result def typecheck(self, element: StructureElement): - return self._typecheck(element, self.default_matches, self.definition) + allowed_matches = self._merge_match_definition_with_default(self.default_matches, + self.definition) + return self._typecheck(element, allowed_matches) class DictBooleanElementConverter(_AbstractDictElementConverter): -- GitLab