<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>______________________________<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"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>