def saved_or_unsaved_state_kept():
    """Restore saved/unsaved state at the end, if needed.

    That is, this context manager makes sure that, once we
    leave the context, the saved/unsaved state is kept the
    same it was at the beginning.
    """
    ### store state before entering context
    changes_were_saved = are_changes_saved()

    ### enter context
    try:
        yield

    ### now that we left the context, restore the state
    ### if it is different from when it was at the
    ### beginning

    finally:

        changes_are_saved = are_changes_saved()

        if changes_were_saved and not changes_are_saved:
            indicate_saved()

        elif not changes_were_saved and changes_are_saved:
            indicate_unsaved()
Restore saved/unsaved state at the end, if needed.

    That is, this context manager makes sure that, once we
    leave the context, the saved/unsaved state is kept the
    same it was at the beginning.
    
nodezator/our3rdlibs/behaviour.py