3 ms·
> Python has no mechanism for embedding or forwarding methods Scala 3 has export statements (https://docs.scala-lang.org/scala3/reference/other-new-features/ex
by thayne 3y ago
> Python has no mechanism for embedding or forwarding methods
Scala 3 has export statements (https://docs.scala-lang.org/scala3/reference/other-new-features/export.html https://docs.scala-lang.org/scala3/reference/other-new-featu...). I wish more OOP languages had something similar, so that there was less boilerplate when composing other objects.
And it is possible to implement something like that in python as a library, although a with a quick search I only found a couple of blog posts on how to implement something yourself.
- uranusjr 3y agoForwarding 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.
- thayne 3y agoIt'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.