vendredi 23 décembre 2016

Differentiate between staticmethd and instancemethod with Class and not its instance

I am trying to find out all instance but not static methods of a class. Furthermore, I am constrained not to create instance of the class (constructor is complex, and required many setups). However, type of both static and instance method is FunctionType as accessed via Class, as shown below.

import types
import inspect

class TestType():

    @staticmethod
    def test_staticmethod():
        pass 

    def test_instancemethod(self):
        pass

test_type = TestType()

print(type(TestType.test_staticmethod)) #<class 'function'>
print(type(TestType.test_instancemethod)) # <class 'function'>

print(type(test_type.test_staticmethod)) #<class 'function'>
print(type(test_type.test_instancemethod)) #<class 'method'>

Are there ways, I can distinguish between instance method and static method, just by accessing them from the Class and not its instance?





Aucun commentaire:

Enregistrer un commentaire