def cast(current, new):
    """Tries to force a new value into the same type as the current."""
    typ = type(current)
    if typ == bool:
        try:
            return bool(int(new))
        except (ValueError, TypeError):
            pass
        try:
            new = new.lower()
        except Exception:
            pass
        if (new=='on') or (new[0] in ('y','t')):
            return True
        if (new=='off') or (new[0] in ('n','f')):
            return False
    else:
        try:
            return typ(new)
        except Exception:
            pass
    print ("Problem setting parameter (now %s) to %s; incorrect type?" % (current, new))
    return current
dataset/ETHPy150Open Exa-Networks/exabgp/lib/exabgp/dep/cmd2.py/cast/original