import sys
class Foo():
@staticmethod
def sm():
return 1
@classmethod
def cm(cls):
return 1
def im(self):
return 1
@property
def pm(self):
return 1
# Not Expected
print("Inspect with type:")
print(type(Foo.sm))
print(type(Foo.cm))
print(type(Foo.im))
print(type(Foo.pm))
# Expected
print("Inspect with __dict__:")
print(type(Foo.__dict__['sm']))
print(type(Foo.__dict__['cm']))
print(type(Foo.__dict__['im']))
print(type(Foo.__dict__['pm']))
klass = getattr(sys.modules[__name__], "Foo")
print(type(klass))
# Not Expected
print("Inspect with type through getattr:")
print(type(getattr(klass, "sm")))
print(type(getattr(klass, "cm")))
print(type(getattr(klass, "im")))
print(type(getattr(klass, "pm")))
# Expected
print("Inspect with __dict__ through getattr:")
print(type(klass.__dict__['sm']))
print(type(klass.__dict__['cm']))
print(type(klass.__dict__['im']))
print(type(klass.__dict__['pm']))
Inspect with type:
<type 'function'>
<type 'instancemethod'>
<type 'instancemethod'>
<type 'property'>
Inspect with __dict__:
<type 'staticmethod'>
<type 'classmethod'>
<type 'function'>
<type 'property'>
<type 'classobj'>
Inspect with type through getattr:
<type 'function'>
<type 'instancemethod'>
<type 'instancemethod'>
<type 'property'>
Inspect with __dict__ through getattr:
<type 'staticmethod'>
<type 'classmethod'>
<type 'function'>
<type 'property'>