from typing import Any
import gc


def _object_for_id(id_: int) -> Any:
    """ Return an object, given its id. """

    # Do a complete garbage collect, to avoid false positives in case the
    # object was still in use recently. In the context of AppSingleLaunch,
    # this would happen if an app was closed, then launched again immediately.
    gc.collect()
    for obj in gc.get_objects():
        if id(obj) == id_:
            return obj
    return None