Stéphane Blondon <stephane.blon...@gmail.com> added the comment: The availability of context manager does not make it mandatory if it does not fit some needs.
> In the last example on https://docs.python.org/3/ > library/mailbox.html#examples inbox is locked and unlocked multiple > times. The with statement couldn't be used here. > I agree with the idea: if the user code needs to manage a lock, using this context manager is a bad idea. By the way, this example does not need to manage the lock because 'inbox' is an instance of mailbox.Maildir so the .lock() and .unlock() calls do nothing for this class ( https://docs.python.org/3/library/mailbox.html#mailbox.Maildir.unlock). > > On https://pymotw.com/3/mailbox/ some examples use the idiom > > mbox = ... > mbox.lock() > try: > ... > finally: > mbox.unlock() > > and others use the idiom > > mbox = ... > mbox.lock() > try: > ... > finally: > mbox.flush() > mbox.close() > In the first example, there is a .flush() call at the end of the try block. In the second case, mbox.flush() is unnecessary because .close() call flush. So I see it like choosing between (.flush() and .unlock()) or .close(). It's what the context manager does. If there is no agreement, perhaps this proposal should be abandoned? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32234> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com