You can use hasattr and callable for the classes themselves (the classes are afterall objects), i.e. something like
if hasattr( C, 'setup' ) and callable( C.setup ): classes_with_setup.append(C)
or, in the sense of understanding the list
classes_with_setup=[ U for U in [A,B,C...] if hasattr(U,'setup') and callable(U.setup)]
to set up a class list with these features.
This methodology detects inheritance:
In [1]: class A(object): ...: def f(self): ...: print 'hi' ...: In [2]: class B(A): ...: pass ...: In [3]: hasattr(A,'f') Out[3]: True In [4]: hasattr(B,'f') Out[4]: True In [5]: hasattr(B,'f') and callable(Bf) Out[5]: True
source share