From 57638fad629cc713c5552e57e4bc84c2e51dbb6a 2013-11-02 01:38:35 From: Thomas Kluyver Date: 2013-11-02 01:38:35 Subject: [PATCH] Don't document classes defined in if __name__ == '__main__' blocks --- diff --git a/docs/sphinxext/apigen.py b/docs/sphinxext/apigen.py index dd5d459..a7bbd5b 100644 --- a/docs/sphinxext/apigen.py +++ b/docs/sphinxext/apigen.py @@ -45,6 +45,14 @@ class FuncClsScanner(ast.NodeVisitor): def has_undoc_decorator(node): return any(isinstance(d, ast.Name) and d.id == 'undoc' \ for d in node.decorator_list) + + def visit_If(self, node): + if isinstance(node.test, ast.Compare) \ + and isinstance(node.test.left, ast.Name) \ + and node.test.left.id == '__name__': + return # Ignore classes defined in "if __name__ == '__main__':" + + self.generic_visit(node) def visit_FunctionDef(self, node): if not (node.name.startswith('_') or self.has_undoc_decorator(node)) \