Skip to content

Class namespace collision between autodoc signatures and docutils >= 0.17 #9872

@ebolyen

Description

@ebolyen

Describe the bug

In docutils version 0.17, the following change was made:

Use HTML text-level tags <small>, <s>, <q>, <dfn>, <var>, <samp>, <kbd>, <i>, <b>, <u>, <mark>, and <bdi> if a unique, matching class value is found in inline and literal elements. Use <ins> and <del> if a unique matching class value is found in inline, literal, or container elements. Use <small> for generated code line numbers.

This appears to conflict with the signature line generated by autodoc, which adds Pygment classes to certain nodes:

sphinx/sphinx/addnodes.py

Lines 332 to 334 in ecee233

class desc_sig_literal_string(desc_sig_element):
"""Node for a string literal in a signature."""
classes = ["s"]

The result is a rather funky looking signature with an unusual DOM:
image
image


This can be fixed by changing the added class to something like pygments-s:
image
image

That said, the above probably won't play nicely with the many existing pygment stylesheets, so I don't really know the best approach.

How to Reproduce

Use a typing.Literal['foo'] in an autodoc'ed signature line.

Expected behavior

No response

Your project

rachis-org/rachis#610

Screenshots

No response

OS

Linux

Python version

3.8

Sphinx version

4.3

Sphinx extensions

sphinx.ext.autodoc

Extra tools

Firefox/Chrome

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions