Skip to main content

rename sphinx references

Project description

This Sphinx extension allows you to rename a code reference prior to Intersphinx looking up the name. It exists to fix up some oddities that occur when you combine type hints (sphinx-autodoc-typehints) with Intersphinx references. For some objects defined in C extension modules, the fully-qualified name of the object is not the same as the one which is documented in the project’s objects.inv file.

For example, Pandas and Requests have some objects which are documented under a different name than their fully-qualified module name:

  • pandas.DataFrame is documented under that name, but when imported, it reports that its fully-qualified name is pandas.core.frame.DataFrame

  • requests.Request reports that it is requests.models.Request

>>> import pandas
>>> pandas.DataFrame
<class 'pandas.core.frame.DataFrame'>
>>> import requests
>>> requests.Request
<class 'requests.models.Request'>

Since sphinx-autodoc-typehints has to rely on this fully-qualified name, and the fully-qualified name doesn’t match the one in these projects’ documentation, the link won’t resolve. You can read more about the issue here.

Solving the Problem

To resolve this, install this module via pip:

pip install sphinx-reference-rename

Add the extension in your conf.py, and put it before sphinx.ext.intersphinx:

extensions = [
    # ...
    "sphinx_reference_rename",
    "sphinx.ext.intersphinx",
    # ...
]

Finally, create a dictionary named sphinx_reference_rename_mapping which maps fully-qualified names to the fixed names. For example, given the examples above:

sphinx_reference_rename_mapping = {
    "pandas.core.frame.DataFrame": "pandas.DataFrame",
    "requests.models.Request": "requests.Request",
}

Now, your sphinx build should succeed!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx-reference-rename-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

sphinx_reference_rename-0.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file sphinx-reference-rename-0.1.0.tar.gz.

File metadata

File hashes

Hashes for sphinx-reference-rename-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b4faecb5eee611c2478439bf7dec5eef5e9a11d24f3972ef6c86130da0ba8e26
MD5 c141b005f26cac5fb6b2108acac8ed34
BLAKE2b-256 d63ddf364aa7a30782a8ee2ee079af93e06a0fb1e13fd5727e006223abfa0967

See more details on using hashes here.

File details

Details for the file sphinx_reference_rename-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_reference_rename-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a72542df4973ad0f843bb32227cc4df48d4840e715c2cb0e587a90212536162
MD5 1555e686910d0818a800e51e52885721
BLAKE2b-256 fab6cb0eca26ab54069b64ba808d40f78de2f1139104074ad0a94958d51a8d37

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page