Georg Brandl  committed 591c7d0

#367: Added automatic exclusion of hidden members in inheritance diagrams, and an option to selectively enable it.

  • Participants
  • Parent commits f977def
  • Branches default

Comments (0)

Files changed (3)

 * #259: HTML table rows now have even/odd CSS classes to enable
   "Zebra styling".
+* #367: Added automatic exclusion of hidden members in inheritance
+  diagrams, and an option to selectively enable it.
 * #306: Added :event:`env-get-outdated` event.
 * C++ domain now supports array definitions.

File doc/ext/inheritance.rst

    ``lib.``, you can give ``:parts: 1`` to remove that prefix from the displayed
    node names.)
+   It also supports a ``private-bases`` flag option; if given, private base
+   classes (those whose name starts with ``_``) will be included.
+   .. versionchanged:: 1.1
+      Added ``private-bases`` option; previously, all bases were always
+      included.
 New config values are:

File sphinx/ext/

     from all the way to the root "object", and then is able to generate a
     graphviz dot graph from them.
-    def __init__(self, class_names, currmodule, show_builtins=False, parts=0):
+    def __init__(self, class_names, currmodule, show_builtins=False,
+                 private_bases=False, parts=0):
         """*class_names* is a list of child classes to show bases from.
         If *show_builtins* is True, then Python builtins will be shown
         self.class_names = class_names
         classes = self._import_classes(class_names, currmodule)
-        self.class_info = self._class_info(classes, show_builtins, parts)
+        self.class_info = self._class_info(classes, show_builtins,
+                                           private_bases, parts)
         if not self.class_info:
             raise InheritanceException('No classes found for '
                                        'inheritance diagram')
             classes.extend(self._import_class_or_module(name, currmodule))
         return classes
-    def _class_info(self, classes, show_builtins, parts):
+    def _class_info(self, classes, show_builtins, private_bases, parts):
         """Return name and bases for all classes that are ancestors of
         def recurse(cls):
             if not show_builtins and cls in builtins:
+            if not private_bases and cls.__name__.startswith('_'):
+                return
             nodename = self.class_name(cls, parts)
             fullname = self.class_name(cls, 0)
             all_classes[cls] = (nodename, fullname, baselist)
             for base in cls.__bases__:
                 if not show_builtins and base in builtins:
-                    return
+                    continue
+                if not private_bases and base.__name__.startswith('_'):
+                    continue
                 baselist.append(self.class_name(base, parts))
                 if base not in all_classes:
     final_argument_whitespace = True
     option_spec = {
         'parts': directives.nonnegative_int,
+        'private-bases': directives.flag,
     def run(self):
             graph = InheritanceGraph(
                 class_names, env.temp_data.get('py:module'),
-                parts=node['parts'])
+                parts=node['parts'],
+                private_bases='private-bases' in self.options)
         except InheritanceException, err:
             return [node.document.reporter.warning(err.args[0],