I want to be able to create a python decorator that automatically “registers” class methods in a global repository (with some properties).
Example code:
class my_class(object):
@register(prop1,prop2)
def my_method( arg1,arg2 ):
# method code here...
@register(prop3,prop4)
def my_other_method( arg1,arg2 ):
# method code here...
I want that when loading is done, somewhere there will be a dict containing:
{ "my_class.my_method" : ( prop1, prop2 )
"my_class.my_other_method" : ( prop3, prop4 ) }
Is this possible?
Not with just a decorator, no. But a metaclass can automatically work with a class after its been created. If your
registerdecorator just makes notes about what the metaclass should do, you can do the following:printing