<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:arial,sans-serif">On Mon, Oct 30, 2017 at 8:30 PM, Drew </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:dwarwick96@gmail.com" target="_blank">dwarwick96@gmail.com</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="auto">Yeah, a flag for IMAP4 objects sounds like it'd solve backwards-compatibility problems. E.g.<br><br></div>
<div dir="auto">imaplib.IMAP4_SSL(..., commit=manual/auto)<br><br></div>
<div dir="auto">As for handling errors with automatic commits, we should probably just defer to whatever Python IO does to remain consistent.<br><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​Yeah, at least if it makes sense here too.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">BTW, it so happens that an old contextlib feature strikes again and allows you to write this in plain English, with punctuation and all:</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">with imaplib.IMAP4_SSL(..) as i, closing(i):</div><div class="gmail_default" style="font-family:monospace,monospace">    ...</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">This one does call .close() regardless of errors, though, and possibly the kind of error may affect whether the commit succeeds or not. Not sure if that matters.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">-- Koos</div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="auto"></div><div><div class="h5">
<div class="gmail_quote">On Oct 30, 2017, at 1:33 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
 <div>
  But maybe if __exit__ is called with an exception it should roll back.
  <br>
  <br>
 </div>In any case it looks like your proposal could break existing code (e.g. code that uses `with` depending on its current behavior, using some other logic to decide whether to commit or not) and that feels difficult to overcome. Perhaps a new method or flag argument can be added to request that the transactions be automatically committed?
 <br>
</div>
<div class="gmail_extra">
 <br>
 <div class="gmail_quote">
  On Mon, Oct 30, 2017 at 10:20 AM, Drew 
  <span dir="ltr"><<a href="mailto:dwarwick96@gmail.com" target="_blank">dwarwick96@gmail.com</a>></span> wrote:
  <br>
  <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   <div dir="auto">
    IMAP4.close closes the selected inbox and commits changes such as deletions. It is not called on IMAP4.__exit__ (only logout is, which doesn't call close in its call stack) however, so:
    <br>
    <br>
   </div> 
   <div dir="auto">
    with imaplib.IMAP4_SSL(...) as i:
    <br>
   </div> 
   <div dir="auto">
        ...
    <br>
    <br>
   </div> 
   <div dir="auto">
    would fail to commit those changes. close must be explicitly invoked i.e.
    <br>
    <br>
   </div> 
   <div dir="auto">
    with imaplib.IMAP4_SSL(...) as i:
    <br>
   </div> 
   <div dir="auto">
        ...
    <br>
   </div> 
   <div dir="auto">
        i.close()
    <br>
    <br>
   </div> 
   <div dir="auto">
    This is counterintuitive however, as the with statement is meant to automatically clean up. Another programmer might come along and delete i.close() because it seems unnecessary. Now changes aren't being committed and the programmer doesn't realize it's because of this weird Python idiosyncracy. 
    <br>
    <br>
   </div> 
   <div dir="auto">
    Python IO such as open commits changes automatically, so I'm not sure why IMAP4 doesn't and only logs out. 
   </div> 
   <br>______________________________
   _________________
   <br> Python-ideas mailing list
   <br> 
   <a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a>
   <br> 
   <a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a>
   <br> Code of Conduct: 
   <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a>
   <br> 
   <br>
  </blockquote>
 </div>
 <br>
 <br clear="all">
 <br>-- 
 <br>
 <div class="m_1514882451231001803gmail_signature" data-smartmail="gmail_signature">
  --Guido van Rossum (
  <a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)
 </div> 
</div></blockquote></div></div></div></div><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven" target="_blank">http://twitter.com/k7hoven</a> +</div>
</div></div>