Jon Waltman avatar Jon Waltman committed d4c6ac1

Closes #617: Fix docstring preparation without included signature: only ignore indentation of one line, not two.

Comments (0)

Files changed (3)

sphinx/ext/autodoc.py

     """
 
     def _find_signature(self, encoding=None):
-        docstrings = Documenter.get_doc(self, encoding, 2)
+        docstrings = Documenter.get_doc(self, encoding)
         if len(docstrings) != 1:
             return
         doclines = docstrings[0]
         # the base name must match ours
         if not self.objpath or base != self.objpath[-1]:
             return
+        # re-prepare docstring to ignore indentation after signature
+        docstrings = Documenter.get_doc(self, encoding, 2)
+        doclines = docstrings[0]
         # ok, now jump over remaining empty lines and set the remaining
         # lines as the new doclines
         i = 1

tests/test_autodoc.py

     assert_result_contains(
         '   rest of docstring', 'method', 'test_autodoc.DocstringSig.meth')
     assert_result_contains(
+        '.. py:method:: DocstringSig.meth2()', 'method',
+        'test_autodoc.DocstringSig.meth2')
+    assert_result_contains(
+        '       indented line', 'method',
+        'test_autodoc.DocstringSig.meth2')
+    assert_result_contains(
         '.. py:classmethod:: Class.moore(a, e, f) -> happiness', 'method',
         'test_autodoc.Class.moore')
 
         rest of docstring
         """
 
+    def meth2(self):
+        """First line, no signature
+        Second line followed by indentation::
+
+            indented line
+        """
+
 class StrRepr(str):
     def __repr__(self):
         return self

tests/test_only_directive.py

 
     def testsects(prefix, sects, indent=0):
         title = sects[0]
-        sprint(' ' * indent + title)
         parent_num = title.split()[0]
         assert prefix == parent_num, \
             'Section out of place: %r' % title
     parts = [getsects(n)
              for n in filter(lambda n: isinstance(n, nodes.section),
                              doctree.children)]
-    sprint('\nChecking headings in only.txt:')
     for i, s in enumerate(parts):
         testsects(str(i+1) + '.', s, 4)
     assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.