[issue32234] Add context management to mailbox.Mailbox

2018-03-28 Thread Stéphane Blondon
Stéphane Blondon 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

[issue32234] Add context management to mailbox.Mailbox

2018-03-23 Thread Serhiy Storchaka
Serhiy Storchaka 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

[issue32234] Add context management to mailbox.Mailbox

2018-03-23 Thread Stéphane Blondon
Stéphane Blondon added the comment: I don't know about something blocking the merge. I sent a message to Barry on Github the 3th january but perhaps it was a wrong timing (too soon after new year). -- ___ Python tracker

[issue32234] Add context management to mailbox.Mailbox

2018-03-22 Thread Cheryl Sabella
Cheryl Sabella added the comment: It looks like Barry was ready to merge this PR in December. Is there anything else that needs to be done for it? Thanks! -- nosy: +csabella ___ Python tracker

[issue32234] Add context management to mailbox.Mailbox

2017-12-18 Thread sblondon
sblondon added the comment: If the access is read-only, the lock is not required [1]. However, I agree it does not worth to be more complex (changing the signature of the subclass or adding another context manager for the lock). I updated the patch and documentation

[issue32234] Add context management to mailbox.Mailbox

2017-12-10 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: It's possible that the Mailman example can just assume that the mailbox will be flushed and unlocked on __exit__(), so it could just call .close(). Then the question is whether entering the CM should lock the mailbox. The two cases are:

[issue32234] Add context management to mailbox.Mailbox

2017-12-09 Thread Yury Selivanov
Change by Yury Selivanov : -- nosy: -yselivanov ___ Python tracker ___ ___

[issue32234] Add context management to mailbox.Mailbox

2017-12-09 Thread sblondon
Change by sblondon : -- keywords: +patch pull_requests: +4673 stage: -> patch review ___ Python tracker ___

[issue32234] Add context management to mailbox.Mailbox

2017-12-06 Thread Nick Coghlan
Nick Coghlan added the comment: I don't know the mailbox API particularly well, but the fact the object offers all three of lock(), unlock() and close() as methods does imply a fair bit of inherent ambiguity. One option would be to offer a module level "mailbox.locked()"

[issue32234] Add context management to mailbox.Mailbox

2017-12-06 Thread sblondon
sblondon added the comment: Currently, the implementation of .close() methods call flush() and unlock() if it's needed. About the ambiguity for the enter call, I think the context manager should provide access to Mailbox, not a lock. If a lock is needed, we could

[issue32234] Add context management to mailbox.Mailbox

2017-12-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There is an ambiguity. What should the context manager do? Should it call a close() on exit (as the OP implies)? Or call lock() on enter and unlock() on exit as in Barry's example? Both behaviors look reasonable. "In the face

[issue32234] Add context management to mailbox.Mailbox

2017-12-06 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: Yes, I think this is a good idea. Would you like to submit a PR for it? FWIW, we have this code in Mailman 3: class Mailbox(MMDF): """A mailbox that interoperates with the 'with' statement.""" def __enter__(self):

[issue32234] Add context management to mailbox.Mailbox

2017-12-06 Thread sblondon
New submission from sblondon : mailbox.Mailbox has a .close() method that should be called at the end of Mailbox use. I think it would be nice to use Mailbox instances with a 'with' statement so .close() will be called it automatically. So there is no need to check