diff --git a/CHANGES b/CHANGES index 42377f34c1e..9d2890b8e93 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,8 @@ Features added * #10366: std domain: Add support for emphasising placeholders in :rst:dir`option` directives through a new ``option_emphasise_placeholders`` configuration option. +* #10439: std domain: Use the repr of some variables when displaying warnings, + making whitespace issues easier to identify. Bugs fixed ---------- diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 8ff199ade50..88a4d28cb8a 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -601,11 +601,11 @@ class StandardDomain(Domain): } dangling_warnings = { - 'term': 'term not in glossary: %(target)s', - 'numref': 'undefined label: %(target)s', - 'keyword': 'unknown keyword: %(target)s', - 'doc': 'unknown document: %(target)s', - 'option': 'unknown option: %(target)s', + 'term': 'term not in glossary: %(target)r', + 'numref': 'undefined label: %(target)r', + 'keyword': 'unknown keyword: %(target)r', + 'doc': 'unknown document: %(target)r', + 'option': 'unknown option: %(target)r', } # node_class -> (figtype, title_getter) @@ -1100,9 +1100,9 @@ def warn_missing_reference(app: "Sphinx", domain: Domain, node: pending_xref else: target = node['reftarget'] if target not in domain.anonlabels: # type: ignore - msg = __('undefined label: %s') + msg = __('undefined label: %r') else: - msg = __('Failed to create a cross reference. A title or caption not found: %s') + msg = __('Failed to create a cross reference. A title or caption not found: %r') logger.warning(msg % target, location=node, type='ref', subtype=node['reftype']) return True diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3ef0e36550d..bae871db1f7 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -39,7 +39,7 @@ """ HTML_WARNINGS = ENV_WARNINGS + """\ -%(root)s/index.rst:\\d+: WARNING: unknown option: &option +%(root)s/index.rst:\\d+: WARNING: unknown option: '&option' %(root)s/index.rst:\\d+: WARNING: citation not found: missing %(root)s/index.rst:\\d+: WARNING: a suitable image for html builder not found: foo.\\* %(root)s/index.rst:\\d+: WARNING: Could not lex literal_block as "c". Highlighting skipped. diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 709dce05db4..9a325a8d469 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -25,7 +25,7 @@ 'fncychap.sty', 'geometry.sty', 'kvoptions.sty', 'hyperref.sty'] LATEX_WARNINGS = ENV_WARNINGS + """\ -%(root)s/index.rst:\\d+: WARNING: unknown option: &option +%(root)s/index.rst:\\d+: WARNING: unknown option: '&option' %(root)s/index.rst:\\d+: WARNING: citation not found: missing %(root)s/index.rst:\\d+: WARNING: a suitable image for latex builder not found: foo.\\* %(root)s/index.rst:\\d+: WARNING: Could not lex literal_block as "c". Highlighting skipped. diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index 772644abea0..5c72a34490b 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -17,7 +17,7 @@ from .test_build_html import ENV_WARNINGS TEXINFO_WARNINGS = ENV_WARNINGS + """\ -%(root)s/index.rst:\\d+: WARNING: unknown option: &option +%(root)s/index.rst:\\d+: WARNING: unknown option: '&option' %(root)s/index.rst:\\d+: WARNING: citation not found: missing %(root)s/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: foo.\\* %(root)s/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: \ diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index baad0c2daa2..ce1636eb28e 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -1369,6 +1369,6 @@ def test_python_python_use_unqualified_type_names_disabled(app, status, warning) @pytest.mark.sphinx('dummy', testroot='domain-py-xref-warning') def test_warn_missing_reference(app, status, warning): app.build() - assert 'index.rst:6: WARNING: undefined label: no-label' in warning.getvalue() - assert ('index.rst:6: WARNING: Failed to create a cross reference. A title or caption not found: existing-label' - in warning.getvalue()) + assert "index.rst:6: WARNING: undefined label: 'no-label'" in warning.getvalue() + assert ("index.rst:6: WARNING: Failed to create a cross reference. " + "A title or caption not found: 'existing-label'") in warning.getvalue() diff --git a/tests/test_ext_autosectionlabel.py b/tests/test_ext_autosectionlabel.py index f950b8f1d9b..f99a6d3f60a 100644 --- a/tests/test_ext_autosectionlabel.py +++ b/tests/test_ext_autosectionlabel.py @@ -74,4 +74,4 @@ def test_autosectionlabel_maxdepth(app, status, warning): html = '
  • Linux

  • ' assert re.search(html, content, re.S) - assert 'WARNING: undefined label: linux' in warning.getvalue() + assert "WARNING: undefined label: 'linux'" in warning.getvalue()