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("Config error: {}: expected {}, found {}".format(
            key, tpe, type(value)))
    return value