[Feature] Autoproxying helpers to automatically register the outputs of functions
Hello!
I've been using the autoproxying features of Pyro to interact with a heavily OO API kicad-python, that returns/yields lots of other rich/custom objects.
I wanted to maintain the existing interface for the sake of remote/local compatibility, so I came up with these helper decorators to automatically register returned objects:
def register_return(method):
"""Decorator to register the return value
of a method in the Pyro daemon."""
@wraps(method)
def wrapper(self, *args, **kwargs):
daemon = self._pyroDaemon
result = method(self, *args, **kwargs)
daemon.register(result)
return result
return wrapper
def register_yielded(method):
"""Decorator to register the return value
of a method in the Pyro daemon."""
@wraps(method)
def wrapper(self, *args, **kwargs):
daemon = self._pyroDaemon
generator = method(self, *args, **kwargs)
for result in generator:
daemon.register(result)
yield result
return wrapper
I feel like there's perhaps a simpler way I'm missing, but if there isn't perhaps this would be a useful util we can include in Pyro for others?
Personally I prefer writing explicit adapter classes to have full control over what is happening, but I can appreciate some simple generic wrappers to get "the bulk done" if you will.
I guess you've looked at the "thirdpartylib" example?
I did! In my case I'm attempting to adapt an existing class that itself already wraps another interface and I don't want to wrap it again since there's quite a lot of methods and returns involved!
Here's a link to one of the files in question: https://github.com/atait/kicad-python/pull/4/files#diff-ecd96c7f47e6b5011bec5c67da46ffe55af26c39ffa89e63b2aa55792008e0a1
@mawildoer did you get kicad-python to work using Pyro5 autoproxies? If so, did you run into https://github.com/irmen/Pyro5/issues/92 ?
@TheSven73 I certainly didn't take a rigorous route through this one and it was a while ago, but I don't recall running into that issue. Sorry I can't be of more help!