Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the repr of the value in some warnings. #10439

Merged
merged 3 commits into from Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions sphinx/domains/std.py
Expand Up @@ -573,11 +573,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 @@ -1072,9 +1072,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 @@ -1340,6 +1340,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()