from typing import Collection


def object_popper(doc: Collection, part, do_pop):
    """Resolve `part` in `doc` attributes, or ``delattr`` it, returning its value or `default`."""
    item = getattr(doc, part)
    if do_pop:
        delattr(doc, part)
    return item