[issue32234] Add context management to mailbox.Mailbox

Serhiy Storchaka report at bugs.python.org
Fri Mar 23 14:52:41 EDT 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Is closing a mailbox in __exit__ the most desirable operation?

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.

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()

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32234>
_______________________________________


More information about the Python-bugs-list mailing list