diff --git a/CHANGES b/CHANGES index f337471e3..b8ab15e8c 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Bugs fixed ---------- * #4669: sphinx.build_main and sphinx.make_main throw NameError +* #4685: autosummary emits meaningless warnings Testing -------- diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 1334084e2..19046112a 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -78,7 +78,7 @@ from sphinx.ext.autodoc.directive import DocumenterBridge, Options from sphinx.ext.autodoc.importer import import_module from sphinx.pycode import ModuleAnalyzer, PycodeError from sphinx.util import import_object, rst, logging -from sphinx.util.docutils import new_document +from sphinx.util.docutils import NullReporter, new_document if TYPE_CHECKING: from typing import Any, Dict, List, Tuple, Type, Union # NOQA @@ -475,6 +475,7 @@ def extract_summary(doc, document): while sentences: summary += sentences.pop(0) + '.' node = new_document('', document.settings) + node.reporter = NullReporter() state_machine.run([summary], node) if not node.traverse(nodes.system_message): # considered as that splitting by period does not break inline markups diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 0fb544f49..a1ae3b31e 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -185,6 +185,14 @@ class LoggingReporter(Reporter): stream, debug, error_handler=error_handler) +class NullReporter(Reporter): + """A dummy reporter; write nothing.""" + + def __init__(self): + # type: () -> None + Reporter.__init__(self, '', 999, 4) + + def is_html5_writer_available(): # type: () -> bool return __version_info__ > (0, 13, 0) diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index f9e217801..f988195a9 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -55,7 +55,7 @@ def test_mangle_signature(): assert res == outp, (u"'%s' -> '%s' != '%s'" % (inp, res, outp)) -def test_extract_summary(): +def test_extract_summary(capsys): from sphinx.util.docutils import new_document from mock import Mock settings = Mock(language_code='', @@ -77,6 +77,9 @@ def test_extract_summary(): 'it does not break sentence.'] assert extract_summary(doc, document) == ' '.join(doc) + _, err = capsys.readouterr() + assert err == '' + @pytest.mark.sphinx('dummy', **default_kw) def test_get_items_summary(make_app, app_params):