M
mk
Hello,
I wrote this class decorator with argument:
def __init__(self, docstring):
self.docstring = docstring
def __call__(self, func):
func.__doc__ = self.docstring
return func
It seems to work:
def f():
pass
'bulba'
Can someone please debug my reasoning if it's incorrect?
1. First, the decorator @ChangeDoc('bulba') instantiates with
__init__(self, 'bulba'), to some class instance, let's call it _decor.
2. Then _decor's __call__ method is called with function f as argument,
changing the docstring and returning the changed f object, like f =
_decor(f) .
Am I missing smth important / potentially useful in typical real-world
applications in that picture?
Regards,
mk
I wrote this class decorator with argument:
def __init__(self, docstring):
self.docstring = docstring
def __call__(self, func):
func.__doc__ = self.docstring
return func
It seems to work:
def f():
pass
'bulba'
Can someone please debug my reasoning if it's incorrect?
1. First, the decorator @ChangeDoc('bulba') instantiates with
__init__(self, 'bulba'), to some class instance, let's call it _decor.
2. Then _decor's __call__ method is called with function f as argument,
changing the docstring and returning the changed f object, like f =
_decor(f) .
Am I missing smth important / potentially useful in typical real-world
applications in that picture?
Regards,
mk