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

autodoc type hints and intersphinx aren't working with the requests public API #9653

Closed
bhrutledge opened this issue Sep 20, 2021 · 6 comments

Comments

@bhrutledge
Copy link

bhrutledge commented Sep 20, 2021

Describe the bug

It looks like autodoc is resolving type hints like requests.Response to their internal definition, e.g. requests.models.Response. This means the intersphinx references to the Requests API docs don’t work, resulting in build messages like WARNING: py:class reference target not found: requests.models.Response.

Based on my limited understanding, I think this might actually be an issue with Requests, but I thought I'd start here.

How to Reproduce

I put an example repo with instructions up at https://github.com/bhrutledge/sphinx-requests-typehints, generated via sphinx-apidoc. The rendered docs are at https://sphinx-requests-typehints.readthedocs.io/en/latest/example_package.html.

Expected behavior

It'd be nice if the types for requests classes in argument defaults and parameters were linked to the Requests documentation.

Your project

https://github.com/bhrutledge/sphinx-requests-typehints

Screenshots

No response

OS

Mac

Python version

3.9.7

Sphinx version

4.2.0

Sphinx extensions

sphinx.ext.autodoc, sphinx.ext.intersphinx

Extra tools

requests

Additional context

No response

@kotfu
Copy link

kotfu commented Oct 8, 2021

I have the same problem. I observe that if you have a docstring on the class which contains:

Uses :class:`requests.Response` to fetch the url

sphinx successfully locates and links the proper page in the requests documentation.

There must be some difference between resolving and locating the type hint and resolving and locating the cross-reference.

@kotfu
Copy link

kotfu commented Oct 9, 2021

I also note that when using Sphinx 4.1 the provided example project does not generate a warning, although it renders the requests.Response type hint as requests.models.Response.

I'm not very familiar with the Sphinx source code, but reviewing the changelog for 4.2 I wonder if #9576 changed this behavior.

@kotfu
Copy link

kotfu commented Oct 9, 2021

Providing a type hint of requests.models.Response doesn't fix the issue either, you get the same error.

kotfu added a commit to tomcatmanager/tomcatmanager that referenced this issue Oct 9, 2021
Sphinx 4.2 has a bug which generates errors rendering type hints for requests: sphinx-doc/sphinx#9653.

Sphinx 4.1 does not generate these errors.
@tk0miya
Copy link
Member

tk0miya commented Oct 9, 2021

It seems the document of requests was built by Sphinx-1.8.5. So an index entry for requests.models.Reponse is not generated. This problem will be resolved by upgrading Sphinx to 4.0 or newer.
https://readthedocs.org/projects/requests/builds/14778070/

Can anyone report this to the requests project?

@bhrutledge
Copy link
Author

Can anyone report this to the requests project?

Done: psf/requests#5954

@bhrutledge
Copy link
Author

Resolved in psf/requests#5956.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants