diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2022-06-16 23:07:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 23:07:25 +0300 |
commit | 1a1491b8a70def8b37c07021b8586fc435103058 (patch) | |
tree | 907d45888c5b769f4dbb9a087fb7a1ee4065d655 | |
parent | f789148fa293d3dfe702588e6d375e1bca411b1a (diff) |
Show the repr of the value in some warnings (#10439)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | sphinx/domains/std.py | 14 | ||||
-rw-r--r-- | tests/test_build_html.py | 2 | ||||
-rw-r--r-- | tests/test_build_latex.py | 2 | ||||
-rw-r--r-- | tests/test_build_texinfo.py | 2 | ||||
-rw-r--r-- | tests/test_domain_py.py | 6 | ||||
-rw-r--r-- | tests/test_ext_autosectionlabel.py | 2 |
7 files changed, 16 insertions, 14 deletions
@@ -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 8ff199ade..88a4d28cb 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 3ef0e3655..bae871db1 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -39,7 +39,7 @@ with "\\?": b?'here: >>>(\\\\|/)xbb<<<((\\\\|/)r)?' """ 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 709dce05d..9a325a8d4 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -25,7 +25,7 @@ STYLEFILES = ['article.cls', 'fancyhdr.sty', 'titlesec.sty', 'amsmath.sty', '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 772644abe..5c72a3449 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -17,7 +17,7 @@ from sphinx.writers.texinfo import TexinfoTranslator 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 baad0c2da..ce1636eb2 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 f950b8f1d..f99a6d3f6 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 = '<li><p><span class="xref std std-ref">Linux</span></p></li>' assert re.search(html, content, re.S) - assert 'WARNING: undefined label: linux' in warning.getvalue() + assert "WARNING: undefined label: 'linux'" in warning.getvalue() |