def getLeg(tensor, leg):
    """
    Get the leg asked from a Tensor.

    Parameters
    ----------
    leg : str or Leg
    
    Returns
    -------
    Leg
        If leg itself is a Leg object, then it is fine. Otherwise, find the leg from the tensor with leg str as a label.
    """
    if (isinstance(leg, str)):
        assert (tensor is not None), "Error: ask leg {} by leg name but tensor is None in getLeg(tensor, leg).".format(leg)
        return tensor.getLeg(leg)
    else:
        return leg