Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intersphinx broken #119

Closed
crusaderky opened this issue Nov 19, 2019 · 3 comments
Closed

intersphinx broken #119

crusaderky opened this issue Nov 19, 2019 · 3 comments

Comments

@crusaderky
Copy link

crusaderky commented Nov 19, 2019

sphinx-autodoc-typehints is generating a huge amount of errors in my project that uses interphinx.

conf.py:

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.intersphinx",
    "sphinx_autodoc_typehints",
]

intersphinx_mapping = {
    "python": ("https://docs.python.org/3/", None),
    "xarray": ("https://xarray.pydata.org/en/stable/", None),
}

set_type_checking_flag = True
typehints_fully_qualified = False
always_document_param_types = True
typehints_document_rtype = True

hello.rst:

.. automodule:: myproject.hello
   :members:
   :undoc-members:
   :show-inheritance:

hello.py:

from typing import Union
import xarray

XarrayType = Union[xarray.DataArray, xarray.Dataset]

class C:
    x: XarrayType

    def __init__(self, x: XarrayType):
        self.x = x

sphinx-build output:

myproject/hello.py:docstring of myproject.hello.C:6: WARNING: py:class reference target not found: xarray.core.dataarray.DataArray
myproject/hello.py:docstring of myproject.hello.C:6: WARNING: py:class reference target not found: xarray.core.dataset.Dataset
myproject/hello.py:docstring of myproject.hello.C:8: WARNING: py:class reference target not found: xarray.core.dataarray.DataArray
myproject/hello.py:docstring of myproject.hello.C:8: WARNING: py:class reference target not found: xarray.core.dataset.Dataset

This is caused by sphinx_autodoct_typehints reading DataArray.__module__; however in the interstphinx objects.inv that is overridden by the module that lists the object in __all__:

$ python -msphinx.ext.intersphinx https://xarray.pydata.org/en/stable/objects.inv | grep '.DataArray '
        xarray.DataArray                         generated/xarray.DataArray.html#xarray.DataArray
        generated/xarray.DataArray               xarray.DataArray                        : generated/xarray.DataArray.html

$  python -c 'import xarray; print(xarray.DataArray.__module__)'
xarray.core.dataarray

This issue is triggered on all packages that define a class in an implementation script and then import it in __init__.py, e.g.:

impl.py:

class C:
    pass

__init__.py:

from .impl import C
__all__ = ("C", )
@agronholm
Copy link
Collaborator

What do you expect me to do about this?

@agronholm
Copy link
Collaborator

Looks like a duplicate of #38, yes?

@crusaderky
Copy link
Author

Yes, it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants