from typing import Any
from typing import Optional


def parse_int(string: Any, base: int = 10) -> Optional[int]:
    """ safely convert an object to int if possible, else return None """

    if isinstance(string, int):
        return string

    try:
        return int(string, base=base)

    except Exception:
        pass

    try:
        return int(string)

    except Exception:
        pass

    return None