If a variable refers to either a function or a class method, how can I find out which one it is and get the class type in case it is a class method especially when the class is still being declared as in the given example.
eg.
def get_info(function_or_method) : print function_or_method class Foo(object): def __init__(self): pass get_info(__init__) def bar(): pass get_info(bar)
Update to question after the first two responses from David and J. F. Sebastian
To reemphasize a point which J.F. Sebastian alluded to, I want to be able to distinguish it when the function is being declared within the class (when the type I am getting is a function and not a bound or unbound method). ie. where the first call to get_info(__init__
) happens I would like to be able to detect that its a method being declared as a part of a class.
This question came up since I am putting a decorator around it and it gets a handle to the init function and I can't actually figure out if a method is being declared within a class or as a stand alone function