sphinx-doc / sphinx-doc/sphinx

Add an option to not create links within a `sig-param` block

Open
#9,599 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Over at Pytorch/vision, we moved from Sphinx 2.x to Sphinx 3.5.4. When rendering python functions with annotations, the rendering looks like this (the raw html is in the detail, broken up by lines).

class torchvision.datasets.Caltech101(root: str, target_type: Union[List[str], str] = 'category', transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False)[source]

We have a few concerns, the primary one is:

  • I couldn't find an option to remove the links to str and bool, we really do not need them and the link formatting is distracting.

Also problematic, but much less so:

  • The formatting makes the page heavier than it needs to be. Is there a way to avoid having so many spans?
  • Spaces are not part of the spans, they are one level up. This greatly reduces the ability to use css formatting, perhaps the "p" class could include the spaces or (maybe better) there is no need for the "p" class, it could be handled like the spaces by the class="sig-param" container.
raw html
<dt id="torchvision.datasets.Caltech101">
<em class="property"><span class="pre">class</span> </em>
<code class="sig-prename descclassname"><span class="pre">torchvision.datasets.</span></code>
<code class="sig-name descname"><span class="pre">Caltech101</span></code>
<span class="sig-paren">(</span>
<em class="sig-param">
    <span class="n"><span class="pre">root</span></span>
    <span class="p"><span class="pre">:</span></span> 
    <span class="n"><a class="reference external has-code" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.9)"><span class="pre">str</span></a></span>
</em>
, 
<em class="sig-param">
    <span class="n"><span class="pre">target_type</span></span>
    <span class="p"><span class="pre">:</span></span> 
    <span class="n">
        <span class="pre">Union</span>
        <span class="p"><span class="pre">[</span></span>
        <span class="pre">List</span>
        <span class="p"><span class="pre">[</span></span>
        <a class="reference external has-code" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.9)"><span class="pre">str</span></a>
        <span class="p"><span class="pre">]</span></span>
        <span class="p"><span class="pre">,</span> </span>
        <a class="reference external has-code" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.9)"><span class="pre">str</span></a>
        <span class="p"><span class="pre">]</span></span>
    </span> 
    <span class="o"><span class="pre">=</span></span> 
    <span class="default_value"><span class="pre">'category'</span></span>
</em>, 
<em class="sig-param">
    <span class="n"><span class="pre">transform</span></span>
    <span class="p"><span class="pre">:</span></span> 
    <span class="n">
        <span class="pre">Optional</span>
        <span class="p"><span class="pre">[</span></span>
        <span class="pre">Callable</span>
        <span class="p"><span class="pre">]</span></span>
     </span> 
     <span class="o"><span class="pre">=</span></span> 
    <span class="default_value"><span class="pre">None</span></span>
</em>, 
<em class="sig-param">
    <span class="n"><span class="pre">target_transform</span></span>
    <span class="p"><span class="pre">:</span></span> 
    <span class="n">
        <span class="pre">Optional</span>
        <span class="p"><span class="pre">[</span></span>
        <span class="pre">Callable</span>
        <span class="p"><span class="pre">]</span></span>
    </span> 
    <span class="o"><span class="pre">=</span></span> 
    <span class="default_value"><span class="pre">None</span></span>
</em>, 
<em class="sig-param">
    <span class="n"><span class="pre">download</span></span>
    <span class="p"><span class="pre">:</span></span> 
    <span class="n">
         <a class="reference external has-code" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.9)"><span class="pre">bool</span></a>
      </span> 
      <span class="o"><span class="pre">=</span></span> 
      <span class="default_value"><span class="pre">False</span></span>
</em>
<span class="sig-paren">)</span>
<a class="reference internal has-code" href="_modules/torchvision/datasets/caltech.html#Caltech101"><span class="viewcode-link"><span class="pre">[source]</span></span></a>
<a class="anchorjs-link " aria-label="Anchor" data-anchorjs-icon="" href="#torchvision.datasets.Caltech101" style="font: 1em / 1 anchorjs-icons; padding-left: 0.375em;"></a>
</dt>
How to Reproduce
$ git clone https://github.com/pytorch/vision
$ cd vision/docs
$ pip install -r requirements.txt
$ make html
$ # open _build/html/datasets.html
Expected behavior

I would expect there to be an option to disable creating links, an option to create light-weight signatures, or something along those lines.

It would also be helpful to have a "guide to formatting" that describes the various classes available for formatting. In this example there are "anchorjs-link ", "default_value", "n", "o","p", "pre", "property", "reference external has-code","reference internal has-code", "sig-name descname", "sig-param", "sig-paren", "sig-prename descclassname", "viewcode-link"

Your project

https://github.com/pytorch/vision/tree/main/docs

Screenshots

No response

OS

linux

Python version

3.8

Sphinx version

3.5.4

Sphinx extensions

'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.mathjax', 'sphinx.ext.napoleon', 'sphinx.ext.viewcode', 'sphinx.ext.duration', 'sphinx_gallery.gen_gallery', 'sphinx_copybutton'

Extra tools

No response

Additional context

We use the pytorch_sphinx_theme based on the RTD theme. Here is the issue that triggered this report https://github.com/pytorch/pytorch_sphinx_theme/pull/139

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the docs directory with the reported Sphinx 3.5.4 reproduction: install requirements.txt, run make html, and inspect _build/html/datasets.html. Trace the autodoc signature rendering responsible for the sig-param links and determine how the requested opt-out should be exposed. Done means the option is documented and prevents those links without breaking signature output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.