In an effort to clean up the main plugin.py file, callback methods could be moved to a callbacks.py file. However, the plugin expects these callback to be defined in plugin.py, so some python magic could be used. If callbacks are renamed with a prefix of callback_, then we could use __getattr__ to intercept the function calls and return a method from a callbacks.py file.
class MagicClass():
def __init__(self, obj):
self.an_obj = obj
def __getattr__(self, method_name):
def method(*args, **kwargs):
print("Handling unknown method: '{}'".format(method_name))
if kwargs:
print("It had the following key word arguments: " + str(kwargs))
if args:
print("It had the following positional arguments: " + str(args))
return getattr(self.an_obj, method_name)(*args, **kwargs)
return method
In an effort to clean up the main
plugin.py
file, callback methods could be moved to acallbacks.py
file. However, the plugin expects these callback to be defined inplugin.py
, so some python magic could be used. If callbacks are renamed with a prefix ofcallback_
, then we could use__getattr__
to intercept the function calls and return a method from acallbacks.py
file.(https://stackoverflow.com/questions/10879806/python-how-to-intercept-a-method-call-which-does-not-exists)