Skip to content

Reference target not found for typing.Literal with negative integer argument #11900

Closed
@nulano

Description

@nulano

Describe the bug

Using a negative number as the value of a typing.Literal type hint causes sphinx to fail to resolve the reference.

How to Reproduce

# conf.py

nitpicky = True
extensions = ["sphinx.ext.intersphinx"]
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
.. py:data:: test
    :type: ~typing.Literal[2]

    This one links to ``https://docs.python.org/3/library/typing.html#typing.Literal``

.. py:data:: test2
    :type: ~typing.Literal[-2]

    This one warns::

        WARNING: py:obj reference target not found: typing.Literal[-2]

Environment Information

Platform:              win32; (Windows-10-10.0.22621-SP0)
Python version:        3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.16.1

Sphinx extensions

["sphinx.ext.intersphinx"]

Additional context

I'm calling sphinx as follows:

"C:\Program Files\Python311\python.exe" -m sphinx.cmd.build -b html -W -n --keep-going -d build/doctrees . build/html 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions