Skip to content

Commit

Permalink
Show the repr of the value in some warnings (#10439)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
  • Loading branch information
ezio-melotti and AA-Turner committed Jun 16, 2022
1 parent f789148 commit 1a1491b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
----------
Expand Down
14 changes: 7 additions & 7 deletions sphinx/domains/std.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_html.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_latex.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_texinfo.py
Expand Up @@ -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: \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_domain_py.py
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/test_ext_autosectionlabel.py
Expand Up @@ -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()

0 comments on commit 1a1491b

Please sign in to comment.