<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:arial,sans-serif">On Wed, Oct 4, 2017 at 3:33 PM, Nick Coghlan </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@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 class="HOEnZb"><div class="h5">On 4 October 2017 at 20:22, Koos Zevenhoven <<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>> wrote:<br>
> On Wed, Oct 4, 2017 at 8:07 AM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
>><br>
>> On 3 October 2017 at 03:13, Koos Zevenhoven <<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>> wrote:<br>
>> > Well, it's not completely unrelated to that. The problem I'm talking<br>
>> > about<br>
>> > is perhaps most easily seen from a simple context manager wrapper that<br>
>> > uses<br>
>> > composition instead of inheritance:<br>
>> ><br>
>> > class Wrapper:<br>
>> >     def __init__(self):<br>
>> >         self._wrapped = SomeContextManager()<br>
>> ><br>
>> >     def __enter__(self):<br>
>> >         print("Entering context")<br>
>> >         return self._wrapped.__enter__()<br>
>> ><br>
>> >     def __exit__(self):<br>
>> >         self._wrapped.__exit__()<br>
>> >         print("Exited context")<br>
>> ><br>
>> ><br>
>> > Now, if the wrapped contextmanager becomes a PEP 521 one with<br>
>> > __suspend__<br>
>> > and __resume__, the Wrapper class is broken, because it does not respect<br>
>> > __suspend__ and __resume__. So actually this is a backwards compatiblity<br>
>> > issue.<br>
>><br>
>> This is a known problem, and one of the main reasons that having a<br>
>> truly transparent object proxy like<br>
>> <a href="https://wrapt.readthedocs.io/en/latest/wrappers.html#object-proxy" rel="noreferrer" target="_blank">https://wrapt.readthedocs.io/<wbr>en/latest/wrappers.html#<wbr>object-proxy</a> as<br>
>> part of the standard library would be highly desirable.<br>
>><br>
><br>
> This is barely related to the problem I describe. The wrapper is not<br>
> supposed to pretend to *be* the underlying object. It's just supposed to<br>
> extend its functionality.<br>
<br>
</div></div>If a wrapper *isn't* trying to act as a transparent object proxy, and<br>
is instead adapting it to a particular protocol, then yes, you'll need<br>
to update the wrapper when the protocol is extended.<br>
<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​Yes, but it still means that the change in the dependency (in this case a standard Python protocol) breaks the wrapper code.​</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Remember that the wrappeR class and the wrappeD class can be implemented in different libraries.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That's not a backwards compatibility problem, because the only way to<br>
encounter it is to update your code to rely on the new extended<br>
protocol - your *existing* code will continue to work fine, since<br>
that, by definition, can't be relying on the new protocol extension.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​No, not all code is "your" code. Clearly this is not a well-known problem. This is a backwards-compatibility problem for the author of the wrappeR, not for the author of the wrappeD object.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">––Koos</div><div class="gmail_default" style="font-family:monospace,monospace">​</div></div></div><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>