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_aliases does not resolve in 3.10 #10455

Open
snorthman opened this issue May 16, 2022 · 5 comments
Open

autodoc_type_aliases does not resolve in 3.10 #10455

snorthman opened this issue May 16, 2022 · 5 comments

Comments

@snorthman
Copy link

snorthman commented May 16, 2022

Describe the bug

I expected

autodoc_type_aliases = {'AliasType': 'mymodule.alias.AliasType'}

to work, but it does nothing in python 3.10, where

from __future__ import annotations

should be unnecessary

How to Reproduce

# alias.py in mymodule
AliasType = int | float

def func() -> AliasType:
  return 0
# conf.py
autodoc_type_aliases = {'AliasType': 'mymodule.alias.AliasType'}

Expected behavior

Resulting build to show

func() -> AliasType

but instead we still find

func() -> int | float

Your project

.

Screenshots

No response

OS

Win

Python version

3.10

Sphinx version

4.5.0

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

@tk0miya
Copy link
Member

tk0miya commented May 22, 2022

from future import annotations

should be unnecessary

Why do you think so? AFAIK, it's still needed.

@JasonGrace2282
Copy link

In addition, autodoc should link the return value of func() to the definition if possible.

@picnixz
Copy link
Member

picnixz commented Dec 30, 2023

Actually, the return type is not formatted at the same place as the parameters list and that's why you end up with signatures where you don't have clickable types.

This is a bug but since autodoc may be completely rewritten at some point, I think we shouldn't implement something that may change entirely in the future. Nothing is planned yet but I am sorry that we probably won't fix this one before deciding what to do with autodoc itself.

@electric-coder
Copy link

@picnixz this can work if using a workaround, as shown with some further diagnostic in this answer from #10785 .

A couple of additional related notes:

  1. This problem will gain renewed traction with Python 3.12's type
  2. Sharing a lot of the same functionality, I haven't been able to get napoleon_type_aliases working at all...

@picnixz
Copy link
Member

picnixz commented Dec 31, 2023

Actually I usually solve these issues by applying my own transformations and resolving references abruptly. However with PEP 695, we need to rethink how we will document type aliases in general, hence I don't want to start something that is likely to be modified.

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

6 participants