Python: can a decorator determine if a function is being defined inside a class?
I'm writing a decorator, and for various annoying reasons[0] it would be expedient to check if the function it is wrapping is being defined stand-alone or as part of a class (and further which classes that new class is subclassing). For example: def my_decorator(f): defined_in_class = ?? print "%r: %s" %(f, defined_in_class) @my_decorator def foo(): pass class Bar(object): @my_decorator def bar(self): pass Should print: <function foo …>: False <function bar …>: True Also, please note: At the point decorators are applied the function will still be a function, not an unbound method, so testing