sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Config option `python_display_short_literal_types` not working

Open user27182 opened this issue 1 year ago • 1 comments

Describe the bug

Setting config value python_display_short_literal_types to True has no effect.

Output from the steps below. image

The docs show Literal, but with this config option Literal should not be shown.

Not sure if this is related to https://github.com/sphinx-doc/sphinx/issues/11473, but the code below is adapted from the MRE posted there.

How to Reproduce

python -m venv .venv
emulate bash -c '. .venv/bin/activate'
pip install sphinx
mkdir src
cat > src/example.py <<EOF
from typing import Literal
from enum import Enum

def foo(x: Literal["foo"]) -> None:
    """Does stuff"""

EOF
cat > src/conf.py <<EOF
import os, sys

sys.path.insert(0, os.path.abspath("."))

extensions = ["sphinx.ext.autodoc"]
python_display_short_literal_types = True
EOF
cat > src/index.rst <<EOF
API reference
=============

.. automodule:: example
    :members:
    :undoc-members:
EOF
sphinx-build -b html src _build

Environment Information

Platform:              darwin; (macOS-13.3.1-arm64-arm-64bit)
Python version:        3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

No response

Additional context

This issue was initially found while trying to add this option as part of https://github.com/pyvista/pyvista/pull/5658

user27182 avatar Feb 21 '24 17:02 user27182

I'll have a look tomorrow. It's possible my PR was incorrect so I'll happily fix what I did.

picnixz avatar Feb 23 '24 19:02 picnixz