The problem is that at the moment the decorated decoder is called, there is no Blah object yet: the class object is built after the class body completes execution. The easiest way to have decorated to store information "somewhere else", for example. function attribute, then the last pass (decorator or class metaclass) retrieves this information in the desired dictionary.
Class decorators are simpler, but they are not inherited (therefore, they will not come from the parent class), while metaclasses are inherited - therefore, if you insist on inheritance, it should be a metaclass. The simplest is, firstly, with the class decorator and the "list" that you have at the beginning of your Q, and not with the "dict" option that you have later:
import inspect def classdecorator(aclass): decorated = [] for name, value in inspect.getmembers(aclass, inspect.ismethod): if hasattr(value, '_decorated'): decorated.append(name) del value._decorated aclass.decorated = decorated return aclass def decorated(afun): afun._decorated = True return afun
Now,
@classdecorator class Blah(object): def one(self): pass @decorated def two(self): pass
gives you the Blah.decorated list that you request in the first part of your Q. Creating instead a dict, as you request in the second part of your Q, simply means changing decorated.append(name) to decorated[name] = value in the above the code, and, of course, the initialization of decorated in the class decorator to an empty dict, not an empty list.
A metaclass variant will use the __init__ metaclass to perform essentially the same post-processing after the class body is built - the __init__ metaclass receives the dict corresponding to the class body as the last argument (but you, you will have to maintain the inheritance yourself, corresponding dealing with any base class similar to a dict or list). Thus, the metaclass approach in practice is only βa little more complicated than the cool decorator, but conceptually it was much more complicated for most people. I will give all the details for the metaclass if you need them, but I will recommend sticking with a simpler class decorator if it is perhaps.