This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sblondon
Recipients barry, cheryl.sabella, ncoghlan, r.david.murray, sblondon, serhiy.storchaka
Date 2018-03-28.21:06:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAOy+up49yWgQ=nUwOgwzsoDOZtGh+PqHPckKAz6fueR3JumOSQ@mail.gmail.com>
In-reply-to <1521831161.37.0.467229070634.issue32234@psf.upfronthosting.co.za>
Content
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?
History
Date User Action Args
2018-03-28 21:06:30sblondonsetrecipients: + sblondon, barry, ncoghlan, r.david.murray, serhiy.storchaka, cheryl.sabella
2018-03-28 21:06:29sblondonlinkissue32234 messages
2018-03-28 21:06:29sblondoncreate