#NEWLINE# def class_hierarchy( cls ) : #NEWLINE# #INDENT# 'Return an unordered sequence of all classes related to cls.\n\n    Traverses diamond hierarchies.\n\n    Fibs slightly: subclasses of builtin types are not returned.  Thus\n    class_hierarchy(class A(object)) returns (A, object), not A plus every\n    class systemwide that derives from object.\n\n    Old-style classes are discarded and hierarchies rooted on them\n    will not be descended.\n\n    ' #NEWLINE# if compat . py2k : #NEWLINE# #INDENT# if isinstance ( cls , types . ClassType ) : #NEWLINE# #INDENT# return list ( ) #NEWLINE# #UNINDENT# #UNINDENT# hier = set ( [ cls ] ) #NEWLINE# process = list ( cls . __mro__ ) #NEWLINE# while process : #NEWLINE# #INDENT# c = process . pop ( ) #NEWLINE# if compat . py2k : #NEWLINE# #INDENT# if isinstance ( c , types . ClassType ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# bases = ( _ for _ in c . __bases__ if ( ( _ not in hier ) and ( not isinstance ( _ , types . ClassType ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# bases = ( _ for _ in c . __bases__ if ( _ not in hier ) ) #NEWLINE# #UNINDENT# for b in bases : #NEWLINE# #INDENT# process . append ( b ) #NEWLINE# hier . add ( cls ) #NEWLINE# #UNINDENT# if compat . py3k : #NEWLINE# #INDENT# if ( ( c . __module__ == 'builtins' ) or ( not hasattr ( c , '__subclasses__' ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( c . __module__ == '__builtin__' ) or ( not hasattr ( c , '__subclasses__' ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# for s in [ _ for _ in c . __subclasses__ ( ) if ( _ not in hier ) ] : #NEWLINE# #INDENT# process . append ( s ) #NEWLINE# hier . add ( s ) #NEWLINE# #UNINDENT# #UNINDENT# return list ( hier )