top | item 38456007

(no title)

uranusjr | 2 years ago

Forwarding itself is trivial, just ~5 lines in __getattr__. The difficulty comes when you need to type check the thing. Fixing that would require some special treatment on the type system side and not really doable with a third party library.

discuss

order

thayne|2 years ago

It's a little more complicated than that if you want to forward some, but not all methods to the delegated object, or have multiple objects you want to delegate to. If you just have __getattr__ delegate everything to one other objects, there isn't much benefit over inheritance.