Class decorator with argument

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top