Commits

Georg Brandl  committed 36da281

Added ``exclude`` argument to :func:`.autodoc.between`. From http://bitbucket.org/mfperzel/sphinx-additions.

  • Participants
  • Parent commits 7e5c300

Comments (0)

Files changed (3)

     instead of PNG images, controlled by the
     :confval:`graphviz_output_format` config value.
   - Added ``alt`` option to :rst:dir:`graphviz` extension directives.
+  - Added ``exclude`` argument to :func:`.autodoc.between`.
 
 * Translations:
 

File sphinx/ext/autodoc.py

             lines.append('')
     return process
 
-def between(marker, what=None, keepempty=False):
+def between(marker, what=None, keepempty=False, exclude=False):
     """
-    Return a listener that only keeps lines between lines that match the
-    *marker* regular expression.  If no line matches, the resulting docstring
-    would be empty, so no change will be made unless *keepempty* is true.
+    Return a listener that either keeps, or if *exclude* is True excludes, lines
+    between lines that match the *marker* regular expression.  If no line
+    matches, the resulting docstring would be empty, so no change will be made
+    unless *keepempty* is true.
 
     If *what* is a sequence of strings, only docstrings of a type in *what* will
     be processed.
         if what and what_ not in what:
             return
         deleted = 0
-        delete = True
+        delete = not exclude
         orig_lines = lines[:]
         for i, line in enumerate(orig_lines):
             if delete:

File tests/test_autodoc.py

     app.disconnect(lid)
 
     lid = app.connect('autodoc-process-docstring', between('---', ['function']))
-    def f():
+    def g():
         """
         first line
         ---
         ---
         third line
         """
-    assert process('function', 'f', f) == ['second line', '']
+    assert process('function', 'g', g) == ['second line', '']
     app.disconnect(lid)
 
+    lid = app.connect('autodoc-process-docstring', between('---', ['function'],
+                                                           exclude=True))
+    def h():
+        """
+        first line
+        ---
+        second line
+        ---
+        third line
+        """
+    assert process('function', 'h', h) == ['first line', 'third line', '']
+    app.disconnect(lid)
 
 def test_new_documenter():
     class MyDocumenter(ModuleLevelDocumenter):