mirror of
				https://github.com/sphinx-doc/sphinx.git
				synced 2025-02-25 18:55:22 -06:00 
			
		
		
		
	Closes #617: Fix docstring preparation without included signature: only ignore indentation of one line, not two.
This commit is contained in:
		| @@ -862,7 +862,7 @@ class DocstringSignatureMixin(object): | |||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     def _find_signature(self, encoding=None): |     def _find_signature(self, encoding=None): | ||||||
|         docstrings = Documenter.get_doc(self, encoding, 2) |         docstrings = Documenter.get_doc(self, encoding) | ||||||
|         if len(docstrings) != 1: |         if len(docstrings) != 1: | ||||||
|             return |             return | ||||||
|         doclines = docstrings[0] |         doclines = docstrings[0] | ||||||
| @@ -877,6 +877,9 @@ class DocstringSignatureMixin(object): | |||||||
|         # the base name must match ours |         # the base name must match ours | ||||||
|         if not self.objpath or base != self.objpath[-1]: |         if not self.objpath or base != self.objpath[-1]: | ||||||
|             return |             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 |         # ok, now jump over remaining empty lines and set the remaining | ||||||
|         # lines as the new doclines |         # lines as the new doclines | ||||||
|         i = 1 |         i = 1 | ||||||
|   | |||||||
| @@ -518,6 +518,12 @@ def test_generate(): | |||||||
|         'test_autodoc.DocstringSig.meth') |         'test_autodoc.DocstringSig.meth') | ||||||
|     assert_result_contains( |     assert_result_contains( | ||||||
|         '   rest of docstring', 'method', 'test_autodoc.DocstringSig.meth') |         '   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( |     assert_result_contains( | ||||||
|         '.. py:classmethod:: Class.moore(a, e, f) -> happiness', 'method', |         '.. py:classmethod:: Class.moore(a, e, f) -> happiness', 'method', | ||||||
|         'test_autodoc.Class.moore') |         'test_autodoc.Class.moore') | ||||||
| @@ -660,6 +666,13 @@ First line of docstring | |||||||
|         rest of docstring |         rest of docstring | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  |     def meth2(self): | ||||||
|  |         """First line, no signature | ||||||
|  |         Second line followed by indentation:: | ||||||
|  |  | ||||||
|  |             indented line | ||||||
|  |         """ | ||||||
|  |  | ||||||
| class StrRepr(str): | class StrRepr(str): | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return self |         return self | ||||||
|   | |||||||
| @@ -39,7 +39,6 @@ def test_sectioning(app): | |||||||
|  |  | ||||||
|     def testsects(prefix, sects, indent=0): |     def testsects(prefix, sects, indent=0): | ||||||
|         title = sects[0] |         title = sects[0] | ||||||
|         sprint(' ' * indent + title) |  | ||||||
|         parent_num = title.split()[0] |         parent_num = title.split()[0] | ||||||
|         assert prefix == parent_num, \ |         assert prefix == parent_num, \ | ||||||
|             'Section out of place: %r' % title |             'Section out of place: %r' % title | ||||||
| @@ -56,7 +55,6 @@ def test_sectioning(app): | |||||||
|     parts = [getsects(n) |     parts = [getsects(n) | ||||||
|              for n in filter(lambda n: isinstance(n, nodes.section), |              for n in filter(lambda n: isinstance(n, nodes.section), | ||||||
|                              doctree.children)] |                              doctree.children)] | ||||||
|     sprint('\nChecking headings in only.txt:') |  | ||||||
|     for i, s in enumerate(parts): |     for i, s in enumerate(parts): | ||||||
|         testsects(str(i+1) + '.', s, 4) |         testsects(str(i+1) + '.', s, 4) | ||||||
|     assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \ |     assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user