How can I reference a class from a specific documentation with Intersphinx?

Question:

I have set up an Intersphinx-mapping for the documentations of Python 2 and Python 3:

intersphinx_mapping = {'py2': ('http://docs.python.org/', None),
                       'py3': ('http://docs.python.org/3', None)}

How can I reference a class from a specific of these two resources? The documentation only mentions :ref:erences and these two attempts do not work:

:ref:`collections.Mapping <py2:collections.Mapping>`
:class:`py3:collections.Mapping`

While this generates an expected link:

:class:`collections.Mapping`
Asked By: funky-future

||

Answers:

The markup below produces working links with your intersphinx_mapping configuration (for py2, I suggest changing the URL to http://docs.python.org/2 to make the version explicit).

Python 2:

:class:`py2:collections.Mapping`

Python 3 (Mapping was moved to collections.abc in Python 3.3):

:class:`py3:collections.abc.Mapping`
Answered By: mzjn

I have some issues with this topic.

Though I included

intersphinx_mapping = {
    'python3': ("https://docs.python.org/3", None),
    'numpy': ('https://numpy.org/doc/stable', None),
    'scipy': ('https://docs.scipy.org/doc/scipy', None),
    'matplotlib': ('https://matplotlib.org/stable', None)
}

the link :class:`typing.Optional` inside a docstring does not yield a link in the html, only the the text is formatted.

Any ideas?

Answered By: hajdukv