Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Load data from YAML files. """
allowed_keys: Optional[Dict[str, type]] = None, required_keys: Optional[Dict[str, type]] = None, key_type: type = str, value_type: Optional[type] = None) -> Dict[Any, Any]: """ Load a dictionary with string keys a YAML or JSON file.
Parameters ---------- path The path of the YAML/JSON file. data Optional data loaded from the file. If this is ``None``, the file is loaded instead. allowed_keys An optional dictionary of allowed keys, where the value is the expected type of the loaded value. If not ``None``, other keys are rejected (unless listed in `required_keys`). required_keys An optional dictionary of required_keys, where the value is the expected type of the loaded value. If not ``None``, specified keys that are missing from the loaded data are an error. key_type The expected type of the keys, ``str`` by default. value_type An optional type. If not ``None`` Returns ------- Dict[str, Any] The loaded dictionary. """
'does not contain a top-level mapping' % path)
'instead of: %s ' 'in the file: %s' % (key.__class__, key_type, path)) 'in the file: %s' % (key, path))
'in the file: %s' % (key, path))
value: Any, expected_type: Optional[type]) -> None: """ Verify the type of an element loaded from a YAML/JSON file.
If the value has an unexpected type, throws a ``RuntimeError``.
Parameters ---------- path The path of the loaded YAML/JSON file. element_kind The kind of element this is (for the error message). element_identifier The identifier of the element (unique within its kind). value The loaded value of the element. expected_type The expected Python class the value should be an instance of. """ 'has a value of the type: %s ' 'instead of the expected type: %s ' 'in the file: %s' % (element_kind, element_identifier, value.__class__, expected_type, path)) |