Commits

Georg Brandl committed e9452df

#520: Provide ``special-members`` option for autodoc directives.

  • Participants
  • Parent commits 2635b07

Comments (0)

Files changed (4)

 
 * #176: Provide ``private-members`` option for autodoc directives.
 
+* #520: Provide ``special-members`` option for autodoc directives.
+
 * #138: Add an ``index`` role, to make inline index entries.
 
 * #443: Allow referencing external graphviz files.

File doc/ext/autodoc.rst

            :members:
            :undoc-members:
 
-   * Private members will be included if the ``private-members`` flag option is
-     given::
+   * "Private" members (that is, those named like ``_private`` or ``__private``)
+     will be included if the ``private-members`` flag option is given.
+
+     .. versionadded:: 1.1
+
+   * Python "special" members (that is, those named like ``__special__``) will
+     be included if the ``special-members`` flag option is given::
 
         .. autoclass:: my.Class
            :members:
            :private-members:
+           :special-members:
+
+     would document both "private" and "special" members of the class.
 
      .. versionadded:: 1.1
 
 
    This value is a list of autodoc directive flags that should be automatically
    applied to all autodoc directives.  The supported flags are ``'members'``,
-   ``'undoc-members'``, ``'private-members'``, ``'inherited-members'`` and
-   ``'show-inheritance'``.
+   ``'undoc-members'``, ``'private-members'``, ``'special-members'``,
+   ``'inherited-members'`` and ``'show-inheritance'``.
 
    If you set one of these flags in this config value, you can use a negated
    form, :samp:`'no-{flag}'`, in an autodoc directive, to disable it once.

File sphinx/ext/autodoc.py

 
         - they are private (except if given explicitly or the private-members
           option is set)
+        - they are special methods (except if given explicitly or the
+          special-members option is set)
         - they are undocumented (except if the undoc-members option is set)
 
         The user can override the skipping decision by connecting to the
             # if isattr is True, the member is documented as an attribute
             isattr = False
 
-            if want_all and membername.startswith('_'):
+            if want_all and membername.startswith('__') and \
+                   membername.endswith('__') and len(membername) > 4:
+                # special __methods__
+                skip = not self.options.special_members
+            elif want_all and membername.startswith('_'):
                 # ignore members whose name starts with _ by default
                 skip = not self.options.private_members
             elif (namespace, membername) in attr_docs:
         'show-inheritance': bool_option, 'synopsis': identity,
         'platform': identity, 'deprecated': bool_option,
         'member-order': identity, 'exclude-members': members_set_option,
-        'private-members': bool_option,
+        'private-members': bool_option, 'special-members': bool_option,
     }
 
     @classmethod
         'members': members_option, 'undoc-members': bool_option,
         'noindex': bool_option, 'inherited-members': bool_option,
         'show-inheritance': bool_option, 'member-order': identity,
-        'exclude-members': members_set_option, 'private-members': bool_option,
+        'exclude-members': members_set_option,
+        'private-members': bool_option, 'special-members': bool_option,
     }
 
     @classmethod
     _special_attrgetters = {}
 
     # flags that can be given in autodoc_default_flags
-    _default_flags = set(['members', 'undoc-members', 'inherited-members',
-                          'show-inheritance', 'private-members'])
+    _default_flags = set([
+        'members', 'undoc-members', 'inherited-members', 'show-inheritance',
+        'private-members', 'special-members',
+    ])
 
     # standard docutils directive settings
     has_content = True

File tests/test_autodoc.py

         inherited_members = False,
         undoc_members = False,
         private_members = False,
+        special_members = False,
         show_inheritance = False,
         noindex = False,
         synopsis = '',