optional_from_dict#
- casm.bset.parsing.optional_from_dict(
- required_type: Any,
- data: dict,
- option: str,
- default_value: Any = None,
- **kwargs,
Parse optional value using required_type.from_dict or raise
Notes
Returns default_value if option key not in data dictionary
If required_type has a from_dict method, that is used and kwargs are passed through. Otherwise, dict.get is used and the value passed to the required_type constructor.
- Parameters:
required_type (Any) – The type of the value to be parsed.
data (dict) – The dictionary containing the value.
option (str) – The key in the dictionary containing the value.
default_value – The default value to return if option key does not exist in data dictionary.
**kwargs – Keyword arguments to be passed through to the from_dict method of required_type, if it exists.
- Returns:
value – A value of the required type.
- Return type:
required_type