import numbers


def coerce_numeric(obj, to_type: type):
    """Gently attempt to coerce between numeric types."""
    # Only try to coerce *to* numbers
    if not issubclass(to_type, numbers.Number):
        return obj

    # Only try to coerce *from* numbers
    if not isinstance(obj, numbers.Number):
        return obj

    # If coercion doesn't work, just return the original object.
    try:
        coerced = to_type(obj)
    except:
        return obj

    return coerced