Skip to content
Snippets Groups Projects
Commit 262cd6de authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: doc strings and move of dict merge

parent e8530c95
No related branches found
No related tags found
2 merge requests!71REL: RElease v0.2.0,!64ENH: Using float converters on integer values
Pipeline #30378 failed
...@@ -644,8 +644,17 @@ class _AbstractDictElementConverter(Converter): ...@@ -644,8 +644,17 @@ class _AbstractDictElementConverter(Converter):
values.update(m2.groupdict()) values.update(m2.groupdict())
return values return values
def _typecheck(self, element: StructureElement, default: Dict, definition: Dict): def _typecheck(self, element: StructureElement, allowed_matches: Dict):
allowed_matches = self._merge_match_definition_with_default(default, definition) """
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)): if (bool(allowed_matches["accept_text"]) and isinstance(element, DictTextElement)):
return True return True
elif (bool(allowed_matches["accept_bool"]) and isinstance(element, DictBooleanElement)): elif (bool(allowed_matches["accept_bool"]) and isinstance(element, DictBooleanElement)):
...@@ -658,6 +667,11 @@ class _AbstractDictElementConverter(Converter): ...@@ -658,6 +667,11 @@ class _AbstractDictElementConverter(Converter):
return False return False
def _merge_match_definition_with_default(self, default: Dict, definition: Dict): 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 = {} result = {}
for key in default: for key in default:
if key in definition: if key in definition:
...@@ -667,7 +681,9 @@ class _AbstractDictElementConverter(Converter): ...@@ -667,7 +681,9 @@ class _AbstractDictElementConverter(Converter):
return result return result
def typecheck(self, element: StructureElement): 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): class DictBooleanElementConverter(_AbstractDictElementConverter):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment