diff --git a/doc/index.rst b/doc/index.rst index 0946fbe9845..1b306a1819b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -191,3 +191,4 @@ usecase-driven documentation, see :ref:`get-started` or :ref:`user-guides`. glossary changes/index examples + diff --git a/sphinx/domains/python/_object.py b/sphinx/domains/python/_object.py index 6a0f0ff7334..8d7a2050d46 100644 --- a/sphinx/domains/python/_object.py +++ b/sphinx/domains/python/_object.py @@ -151,7 +151,24 @@ def make_xrefs( class PyField(PyXrefMixin, Field): - pass + def make_xref( + self, + rolename: str, + domain: str, + target: str, + innernode: type[TextlikeNode] = nodes.emphasis, + contnode: Node | None = None, + env: BuildEnvironment | None = None, + inliner: Inliner | None = None, + location: Node | None = None, + ) -> Node: + if rolename == 'class' and target == 'None': + # None is not a type, so use obj role instead. + rolename = 'obj' + + return super().make_xref( + rolename, domain, target, innernode, contnode, env, inliner, location + ) class PyGroupedField(PyXrefMixin, GroupedField): @@ -159,7 +176,24 @@ class PyGroupedField(PyXrefMixin, GroupedField): class PyTypedField(PyXrefMixin, TypedField): - pass + def make_xref( + self, + rolename: str, + domain: str, + target: str, + innernode: type[TextlikeNode] = nodes.emphasis, + contnode: Node | None = None, + env: BuildEnvironment | None = None, + inliner: Inliner | None = None, + location: Node | None = None, + ) -> Node: + if rolename == 'class' and target == 'None': + # None is not a type, so use obj role instead. + rolename = 'obj' + + return super().make_xref( + rolename, domain, target, innernode, contnode, env, inliner, location + ) class PyObject(ObjectDescription[tuple[str, str]]): diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index dc19754cbf2..ab19beeed1a 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -261,6 +261,7 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s # things that are not types if cls is None or cls == types.NoneType: return ':py:obj:`None`' + if cls is Ellipsis: return '...' if isinstance(cls, str):