<div dir="auto"><div style="font-family:sans-serif" class="elided-text" dir="auto">Hi all, It was suggested that I start a new thread, because the other thread drifted away from its original topic. So here, in case someone is interested:</div><div style="font-family:sans-serif" class="elided-text" dir="auto"><br></div><div style="font-family:sans-serif" class="elided-text" dir="auto">On Oct 2, 2017 17:03, "Koos Zevenhoven <<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div style="font-family:monospace,monospace"><span style="font-family:'arial',sans-serif">On Mon, Oct 2, 2017 at 6:42 AM, Guido van Rossum </span><span dir="ltr" style="font-family:'arial',sans-serif"><<a href="mailto:guido@python.org">guido@python.org</a>></span><span style="font-family:'arial',sans-serif"> wrote:</span><br></div></div><div><div class="elided-text"><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="elided-text">On Sun, Oct 1, 2017 at 1:52 PM, Koos Zevenhoven <span dir="ltr"><<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><div><div class="elided-text">On Oct 1, 2017 19:26, "Guido van Rossum" <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Your PEP is currently incomplete. If you don't finish it, it is not even a contender. But TBH it's not my favorite anyway, so you could also just withdraw it. </div><div><div></div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I can withdraw it if you ask me to, but I don't want to withdraw it without any reason. I haven't changed my mind about the big picture. OTOH, PEP 521 is elegant and could be used to implement PEP 555, but 521 is almost certainly less performant and has some problems regarding context manager wrappers that use composition instead of inheritance.</div></div></blockquote><div><br></div><div>It is my understanding that PEP 521 (which proposes to add optional __suspend__ and __resume__ methods to the context manager protocol, to be called whenever a frame is suspended or resumed inside a `with` block) is no longer a contender because it would be way too slow. I haven't read it recently or thought about it, so I don't know what the second issue you mention is about (though it's presumably about the `yield` in a context manager implemented using a generator decorated with `@contextlib.contextmanager`).</div><div><br></div></div></div></div></blockquote><div><br></div></div><div><div style="font-family:monospace,monospace">​Well, it's not completely unrelated to that. The problem I'm talking about is perhaps most easily seen from a simple context manager wrapper that uses composition instead of inheritance:</div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">class Wrapper:</div><div style="font-family:monospace,monospace">    def __init__(self):</div><div style="font-family:monospace,monospace">        self._wrapped = SomeContextManager()</div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">    def __enter__(self):</div><div style="font-family:monospace,monospace">        print("Entering context")</div><div style="font-family:monospace,monospace">        return self._wrapped.__enter__()</div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">    def __exit__(self):</div><div style="font-family:monospace,monospace">        self._wrapped.__exit__()</div><div style="font-family:monospace,monospace">        print("Exited context")</div><div style="font-family:monospace,monospace">   </div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">Now, if the wrapped contextmanager becomes a PEP 521 one with __suspend__ and __resume__, the Wrapper class is broken, because it does not respect __suspend__ and __resume__. So actually this is a backwards compatiblity issue. </div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">But if the wrapper is made using inheritance, the problem goes away:</div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">class Wrapper(SomeContextManager):</div><div style="font-family:monospace,monospace">    def __enter__(self):</div><div style="font-family:monospace,monospace">        print("Entering context")</div><div style="font-family:monospace,monospace">        return super().__enter__()</div><div style="font-family:monospace,monospace">    </div><div style="font-family:monospace,monospace">    def __exit__(self):</div><div style="font-family:monospace,monospace">        super().__exit__()</div><div style="font-family:monospace,monospace">        print("Exited context")</div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">Now the wrapper cleanly inherits the new optional __suspend__ and __resume__ from the wrapped context manager type. </div><font color="#888888"><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace"><br></div><div style="font-family:monospace,monospace">––Koos</div></font></div><font color="#888888"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div></div></blockquote></font></div><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven">http://twitter.com/k7hoven</a> +</div></font></div></div></blockquote></div><br></div>