Extract the currently set field from a Value structure

def getValueFromValue(value):
    """
    Extract the currently set field from a Value structure
    """
    if type(value) != common.AttributeValue:
        raise TypeError(
            "Expected an AttributeValue, but got {}".format(type(value)))
    if value.WhichOneof("value") is None:
        raise AttributeError("Nothing set for {}".format(value))
    return getattr(value, value.WhichOneof("value"))