def inherits_from(obj, parent):
 if callable(obj):
  obj_paths = [('%s.%s' % (mod.__module__, mod.__name__)) for mod in obj.mro()]
 else:
  obj_paths = [('%s.%s' % (mod.__module__, mod.__name__)) for mod in obj.__class__.mro()]
 if isinstance(parent, basestring):
  parent_path = parent
 elif callable(parent):
  parent_path = ('%s.%s' % (parent.__module__, parent.__name__))
 else:
  parent_path = ('%s.%s' % (parent.__class__.__module__, parent.__class__.__name__))
 return any((1 for obj_path in obj_paths if (obj_path == parent_path)))

def inherits_from ( obj , parent ) : if callable ( obj ) : obj_paths = [ ( '%s.%s' % ( mod . __module__ , mod . __name__ ) ) for mod in obj . mro ( ) ] else : obj_paths = [ ( '%s.%s' % ( mod . __module__ , mod . __name__ ) ) for mod in obj . __class__ . mro ( ) ] if isinstance ( parent , basestring ) : parent_path = parent elif callable ( parent ) : parent_path = ( '%s.%s' % ( parent . __module__ , parent . __name__ ) ) else : parent_path = ( '%s.%s' % ( parent . __class__ . __module__ , parent . __class__ . __name__ ) ) return any ( ( 1 for obj_path in obj_paths if ( obj_path == parent_path ) ) )
takes an object and tries to determine if it inherits at *any* distance from parent .