def _assert_type(data, key, tpe, default=None):
    """Extract and verify if a key in a dictionary has a given type."""
    value = data.get(key, default)
    if not isinstance(value, tpe):
        raise ValueError(
            f'Config error: {key}: expected {tpe}, found {type(value)}')
    return value
