[Python-Dev] Inheritance vs composition in backcompat (PEP521) (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Oct 4 01:07:31 EDT 2017
- Previous message (by thread): [Python-Dev] Inheritance vs composition in backcompat (PEP521)
- Next message (by thread): [Python-Dev] Inheritance vs composition in backcompat (PEP521)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 3 October 2017 at 03:13, Koos Zevenhoven <k7hoven at gmail.com> wrote:
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:
class Wrapper: def init(self): self.wrapped = SomeContextManager() def enter(self): print("Entering context") return self.wrapped.enter() def exit(self): self.wrapped.exit() print("Exited context")
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.
This is a known problem, and one of the main reasons that having a truly transparent object proxy like https://wrapt.readthedocs.io/en/latest/wrappers.html#object-proxy as part of the standard library would be highly desirable.
Actually getting such a proxy defined, implemented, and integrated isn't going to be easy though, so while Graham (Dumpleton, the author of wrapt) is generally amenable to the idea, he doesn't have the time or inclination to do that work himself.
In the meantime, we mostly work around the problem by defining new protocols rather than extending existing ones, but it still means it takes longer than it otherwise for full support for new interfaces to ripple out through various object proxying libraries (especially for hard-to-proxy protocols like the new asynchronous ones that require particular methods to be defined as coroutines).
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] Inheritance vs composition in backcompat (PEP521)
- Next message (by thread): [Python-Dev] Inheritance vs composition in backcompat (PEP521)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]