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 typehints do not create link for parametrized types #9194

Closed
anntzer opened this issue May 9, 2021 · 5 comments
Closed

autodoc typehints do not create link for parametrized types #9194

anntzer opened this issue May 9, 2021 · 5 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented May 9, 2021

Describe the bug

autodoc typehints normally generate a link to the hinted type, but do not do so for parametrized types.

To Reproduce
Steps to reproduce the behavior:

$ cat >project.py <<EOF
from typing import Literal

def func(x: Literal["a", "b"], y: int):
    """
    :param x: The x.
    :param y: The y.
    """
EOF
sphinx-apidoc . -o . -F -A me -V 0.0 --extensions sphinx.ext.intersphinx
PYTHONPATH=. make O=-Dautodoc_typehints=description html

and open _build/html/project.html

Expected behavior
Literal (in the parameter description) should link to typing.Literal in CPython's docs, just like int does.

Your project
N/A

Screenshots
s

Environment info

  • OS: linux
  • Python version: 3.9.4
  • Sphinx version: 4.0.0
  • Sphinx extensions: intersphinx, autodoc
  • Extra tools: N/A

Additional context
N/A

@tk0miya tk0miya added this to the 4.1.0 milestone May 9, 2021
@tk0miya
Copy link
Member

tk0miya commented May 9, 2021

Duplicated with #9195? Closing.

@tk0miya tk0miya closed this as completed May 9, 2021
@tk0miya tk0miya reopened this May 9, 2021
@tk0miya
Copy link
Member

tk0miya commented May 9, 2021

Oh, sorry. I understood these are different topic. Reopened now.

@tk0miya tk0miya modified the milestones: 4.1.0, 4.2.0 Jul 10, 2021
@pradyunsg
Copy link
Contributor

pradyunsg commented Aug 31, 2021

The issue seems to be stemming from

annotation[param.name] = typing.stringify(param.annotation)
-- since the types coming from typing are "stringified" and not being passed through intersphinx.

@pradyunsg
Copy link
Contributor

I guess the fix here is to pass these through typing.restify instead?

@tk0miya tk0miya modified the milestones: 4.2.0, 4.3.0 Sep 12, 2021
@tk0miya tk0miya modified the milestones: 4.3.0, 4.4.0 Nov 9, 2021
@tk0miya
Copy link
Member

tk0miya commented Nov 29, 2021

I guess the fix here is to pass these through typing.restify instead?

No, it will generate incorrect mark-ups:

.. py:function:: func(x: :py:class:`Literal`\["a", "b"], y: :py:class:`int`)

tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 19, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 19, 2021
…inked

This converts Literal types to valid references when
`autodoc_unqualified_typehints` option enabled.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 20, 2021
This converts types in typing module to valid references when
`autodoc_unqualified_typehints` option enabled.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 20, 2021
This converts types in typing module to valid references when
`autodoc_unqualified_typehints` option enabled.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 24, 2021
… signature

To create hyperlinks to container types automatically, this prepends the
module names for the types under "typing" module.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 24, 2021
… signature

To create hyperlinks to container types automatically, this prepends the
module names for the types under "typing" module.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 24, 2021
… signature

To create hyperlinks to container types automatically, this prepends the
module names for the types under "typing" module.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 25, 2021
… signature

To create hyperlinks to container types automatically, this prepends the
module names for the types under "typing" module.
tk0miya added a commit that referenced this issue Dec 26, 2021
Fix #9194: autodoc: types in typing module are not hyperlinked
AA-Turner pushed a commit to AA-Turner/sphinx that referenced this issue Dec 29, 2021
This converts types in typing module to valid references when
`autodoc_unqualified_typehints` option enabled.
AA-Turner pushed a commit to AA-Turner/sphinx that referenced this issue Dec 29, 2021
… signature

To create hyperlinks to container types automatically, this prepends the
module names for the types under "typing" module.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2022
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