diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index c68a54a0..b7d10de9 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -88,11 +88,14 @@ def is_docstring_section(node): for sibling_section in sibling_sections: if not sibling_section.children: continue - last_child = sibling_section.children[-1] - if not isinstance(last_child, comment): - continue - if last_child.rawsource.strip() == DEDUPLICATION_TAG.strip(): - return True + + for child in sibling_section.children[::-1]: + if not isinstance(child, comment): + continue + + if child.rawsource.strip() == DEDUPLICATION_TAG.strip(): + return True + return False diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index 9fc8fb6b..73837759 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -1,4 +1,5 @@ import os.path as op +import re import shutil import pytest @@ -65,3 +66,27 @@ def test_my_function(sphinx_app): assert '*args' in html # check xref (iterable should link using xref): assert 'glossary.html#term-iterable' in html + + +def test_reference(sphinx_app): + """Test for bad references""" + out_dir = sphinx_app.outdir + html_files = [ + ["index.html"], + ["generated", "numpydoc_test_module.my_function.html"], + ["generated", "numpydoc_test_module.MyClass.html"], + ] + + expected_lengths = [3, 1, 1] + + for html_file, expected_length in zip(html_files, expected_lengths): + html_file = op.join(out_dir, *html_file) + + with open(html_file, 'r') as fid: + html = fid.read() + + reference_list = re.findall(r'(.*)<\/a>', html) + + assert len(reference_list) == expected_length + for ref in reference_list: + assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1 diff --git a/numpydoc/tests/tinybuild/index.rst b/numpydoc/tests/tinybuild/index.rst index a078ff88..9d5c1d9c 100644 --- a/numpydoc/tests/tinybuild/index.rst +++ b/numpydoc/tests/tinybuild/index.rst @@ -2,3 +2,4 @@ numpydoc_test_module ==================== .. automodule:: numpydoc_test_module + :members: diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 85d990ca..3c23dc4c 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -7,6 +7,13 @@ MyClass my_function + +Reference [1]_ + +References +---------- +.. [1] https://numpydoc.readthedocs.io + """ __all__ = ['MyClass', 'my_function'] @@ -15,22 +22,33 @@ class MyClass(object): """A class. + Reference [2]_ + Parameters ---------- *args : iterable Arguments. **kwargs : dict Keyword arguments. + + References + ---------- + .. [2] https://numpydoc.readthedocs.io """ def __init__(self, *args, **kwargs): pass + def example(self): + """Exampel function + """ + pass + def my_function(*args, **kwargs): """Return None. - See [1]_. + See [3]_. Parameters ---------- @@ -46,6 +64,6 @@ def my_function(*args, **kwargs): References ---------- - .. [1] https://numpydoc.readthedocs.io + .. [3] https://numpydoc.readthedocs.io """ return None