Skip to content

Commit f09abc8

Browse files
committed
Test autosummary-like behaviour
And remove quirky 'or not desc' case
1 parent 5f641a1 commit f09abc8

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

numpydoc/docscrape_sphinx.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _str_param_list(self, name, fake_autosummary=False):
107107
param_obj = None
108108
obj_doc = pydoc.getdoc(param_obj)
109109

110-
if param_obj and (obj_doc or not desc):
110+
if param_obj and obj_doc:
111111
# Referenced object has a docstring
112112
autosum += [" %s%s" % (autosum_prefix, param)]
113113
# TODO: add signature to display as in autosummary
@@ -122,7 +122,8 @@ def _str_param_list(self, name, fake_autosummary=False):
122122
desc = re.split('\n\s*\n', obj_doc.strip(), 1)[0]
123123
# XXX: Should this have DOTALL?
124124
# It does not in autosummary
125-
m = re.search(r"^([A-Z].*?\.)(?:\s|$)", desc)
125+
m = re.search(r"^([A-Z].*?\.)(?:\s|$)",
126+
' '.join(desc.split()))
126127
if m:
127128
desc = m.group(1).strip()
128129
else:
@@ -183,7 +184,7 @@ def _str_member_list(self, name):
183184
or inspect.isgetsetdescriptor(param_obj)):
184185
param_obj = None
185186

186-
if param_obj and (pydoc.getdoc(param_obj) or not desc):
187+
if param_obj and pydoc.getdoc(param_obj):
187188
# Referenced object has a docstring
188189
autosum += [" %s%s" % (prefix, param)]
189190
else:

numpydoc/tests/test_docscrape.py

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,17 @@ def test_duplicate_signature():
899899
Current time.
900900
y : ndarray
901901
Current variable values.
902-
x : float
903-
Some parameter
902+
903+
* hello
904+
* world
905+
an_attribute : float
906+
The docstring is printed instead
907+
no_docstring : str
908+
But a description
909+
no_docstring2 : str
910+
multiline_sentence
911+
midword_period
912+
no_period
904913
905914
Methods
906915
-------
@@ -936,8 +945,17 @@ def test_class_members_doc():
936945
Current time.
937946
y : ndarray
938947
Current variable values.
939-
x : float
940-
Some parameter
948+
949+
* hello
950+
* world
951+
an_attribute : float
952+
The docstring is printed instead
953+
no_docstring : str
954+
But a description
955+
no_docstring2 : str
956+
multiline_sentence
957+
midword_period
958+
no_period
941959
942960
Methods
943961
-------
@@ -954,10 +972,38 @@ def test_class_members_doc():
954972
def test_class_members_doc_sphinx():
955973
class Foo:
956974
@property
957-
def x(self):
975+
def an_attribute(self):
958976
"""Test attribute"""
959977
return None
960978

979+
@property
980+
def no_docstring(self):
981+
return None
982+
983+
@property
984+
def no_docstring2(self):
985+
return None
986+
987+
@property
988+
def multiline_sentence(self):
989+
"""This is a
990+
sentence. It spans multiple lines."""
991+
return None
992+
993+
@property
994+
def midword_period(self):
995+
"""The sentence for numpy.org."""
996+
return None
997+
998+
@property
999+
def no_period(self):
1000+
"""This does not have a period
1001+
so we truncate its summary to the first linebreak
1002+
1003+
Apparently.
1004+
"""
1005+
return None
1006+
9611007
doc = SphinxClassDoc(Foo, class_doc_txt)
9621008
non_blank_line_by_line_compare(str(doc),
9631009
"""
@@ -983,15 +1029,30 @@ def x(self):
9831029
Current time.
9841030
**y** : ndarray
9851031
Current variable values.
986-
:obj:`x <x>` : float
1032+
1033+
* hello
1034+
* world
1035+
:obj:`an_attribute <an_attribute>` : float
9871036
Test attribute
1037+
**no_docstring** : str
1038+
But a description
1039+
**no_docstring2** : str
1040+
:obj:`multiline_sentence <multiline_sentence>`
1041+
This is a sentence.
1042+
:obj:`midword_period <midword_period>`
1043+
The sentence for numpy.org.
1044+
:obj:`no_period <no_period>`
1045+
This does not have a period
9881046
9891047
..
9901048
HACK to make autogen generate docs:
9911049
.. autosummary::
9921050
:toctree:
9931051
994-
x
1052+
an_attribute
1053+
multiline_sentence
1054+
midword_period
1055+
no_period
9951056
9961057
.. rubric:: Methods
9971058

0 commit comments

Comments
 (0)