3

I use any as the default role when for building my documentation with Sphinx, which works as intended by automatically linking some marked references and formatting the others as code while avoiding cluttering the docstrings with markup.

Unfortunately, when building the documentation this way, the output is cluttered with warnings for references for which any could not find a target:

WARNING: 'any' reference target not found: […]

Is there any way to suppress these warnings?

So far, the only resource I could find on this manner was this question, which is however specific about an entirely different warning.

Community
  • 1
  • 1
Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54
  • From the recent Sphinx documentation there is an option for [suppress_warnings](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-suppress_warnings), the message might be suppressed by adding to `conf.py` the following `suppress_warnings = ['ref.python']`, although this will also suppress many other warnings as well. – Yogev Neumann Nov 25 '22 at 21:15

1 Answers1

4

I filed a feature request for this, which was rejected but yielded a solution nontheless (thanks to Takeshi Komiya):

Add the following to conf.py:

def on_missing_reference(app, env, node, contnode):
    if node['reftype'] == 'any':
        return contnode
    else:
        return None

def setup(app):
    app.connect('missing-reference', on_missing_reference)
Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54