def try_int(x):
    """Converts the input to an int, or returns None if conversion fails"""
    if x is None:
        return x

    try:
        return int(x)
    except ValueError:
        return None