def get_class_traits(klass):
 source = inspect.getsource(klass)
 cb = CommentBlocker()
 cb.process_file(StringIO(source))
 mod_ast = compiler.parse(source)
 class_ast = mod_ast.node.nodes[0]
 for node in class_ast.code.nodes:
  if isinstance(node, compiler.ast.Assign):
   name = node.nodes[0].name
   rhs = unparse(node.expr).strip()
   doc = strip_comment_marker(cb.search_for_comment(node.lineno, default=''))
   (yield (name, rhs, doc))

def get_class_traits ( klass ) : source = inspect . getsource ( klass ) cb = CommentBlocker ( ) cb . process_file ( StringIO ( source ) ) mod_ast = compiler . parse ( source ) class_ast = mod_ast . node . nodes [ 0 ] for node in class_ast . code . nodes : if isinstance ( node , compiler . ast . Assign ) : name = node . nodes [ 0 ] . name rhs = unparse ( node . expr ) . strip ( ) doc = strip_comment_marker ( cb . search_for_comment ( node . lineno , default = '' ) ) ( yield ( name , rhs , doc ) )
yield all of the documentation for trait definitions on a class object .