python-sphinx

Sphinx nit-picky mode but only for links I explicitly wrote


I tried turning on Sphinx's nit-picky mode (-n) to catch any broken links I might have accidentally made. However, it spews out errors for all the places where I've documented types. In some cases I've described types semantically (e.g. "3D array"), but it does it even for types extracted from type hints (even with intersphinx set up to pull Python types). For example, for this module

from typing import Callable

def foo(x: Callable[..., int]):
    pass

I get the error docstring of myproj.foo:: WARNING: py:class reference target not found: Callable[..., int]. That's with only sphinx.ext.autodoc and sphinx.ext.intersphinx extensions and a freshly-generated conf.py.

Is there some way to prevent Sphinx from trying to generate links for type information, or at least stop it complaining when they don't exist while still telling me about bad links in my hand-written documentation?

I'm using Sphinx 3.0.3.


Solution

  • Perhaps nitpick_ignore will do what you want? In your conf.py, something like this:

    nitpick_ignore = [
        ("py:class", "Callable"),
    ]
    

    I'm not sure of the exact values in the tuple that should be used, but I got the idea from this issue and a linked commit.