python inspect get methods decorated with @property
The @property
decorator produces a property
object, not a function or a method. It is this object that calls the function it has stored in the .fget
, .fset
and .fdel
attributes on that object when accessed (through the descriptor protocol).
You'll have to explicitly test for that object type:
methods = inspect.getmembers(cls[1], inspect.ismethod)properties = inspect.getmembers(cls[1], lambda o: isinstance(o, property))
or
methods_and_properties = inspect.getmembers( cls[1], lambda o: isinstance(o, (property, types.MethodType)))
Note that the same limitations apply to classmethod
and staticmethod
objects.