diff --git a/src/caoscrawler/converters.py b/src/caoscrawler/converters.py index 22dc27a912d5028ca5ddbf3d77daac64541e08eb..84928d62fd1786b87058086af113a8b8dc572062 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):