From c222503f42fd47ef973b0cfd49457de96f12a694 Mon Sep 17 00:00:00 2001 From: c-holtermann Date: Fri, 19 Jun 2020 19:08:00 +0200 Subject: [PATCH] add method decorate_method to function_class.py ClassFromFunctions.decorate_method() allows to provide positional and keyword arguments for the decorator call besides the wrapped method. --- bindings/python/function_class.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bindings/python/function_class.py b/bindings/python/function_class.py index fc99cc80fa..31559f6c16 100644 --- a/bindings/python/function_class.py +++ b/bindings/python/function_class.py @@ -207,6 +207,22 @@ class ClassFromFunctions(object): setattr( cls, function_name, decorator( getattr(cls, function_name) ) ) + @classmethod + def decorate_method(cls, decorator, method_name, *args, **kargs): + """! decorate method method_name of class cls with decorator decorator + + in difference to decorate_functions() this allows to provide additional + arguments for the decorator function. + + arguments: + @param cls: class + @param decorator: function to decorate method + @param method_name: name of method to decorate (string) + @param *args: positional arguments for decorator + @param **kargs: keyword arguments for decorator""" + setattr(cls, method_name, + decorator(getattr(cls, method_name), *args, **kargs)) + def method_function_returns_instance(method_function, cls): """A function decorator that is used to decorate method functions that return instance data, to return instances instead.