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: autodoc_type_aliases does not effect to the type annotation for instance attributes #8541

Closed
tk0miya opened this issue Dec 16, 2020 · 0 comments

Comments

@tk0miya
Copy link
Member

tk0miya commented Dec 16, 2020

Describe the bug
autodoc: autodoc_type_aliases does not effect to the type annotation for instance attributes

To Reproduce

# example.py
from __future__ import annotations

class Foo:
    def __init__(self):
        self.attr: myint = None  #: docstring
# index.rst

.. autoattribute:: example.Foo.attr
# conf.py
autodoc_type_aliases = {'myint': 'mod.myint'}

Expected behavior
The type annotations for the instance variables also changed by autodoc_type_aliases

Your project
No

Screenshots
No

Environment info

  • OS: Mac
  • Python version: 3.9.1
  • Sphinx version: HEAD of 3.x
  • Sphinx extensions: sphinx.ext.autodoc
  • Extra tools: No

Additional context
No

@tk0miya tk0miya added this to the 3.4.0 milestone Dec 16, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 16, 2020
…ce attrs

So far, autodoc obtains type annotations of instance attributes by
ModuleAnalyzer directly.  As a result, autodoc_type_aliases are ignored
for these variables.

This goes to merge type annotations from the class itself and
ModuleAnalyzer's, and get type annotations using `typing.get_type_hints()`
to apply autodoc_type_aliases.
tk0miya added a commit that referenced this issue Dec 17, 2020
Fix #8541: autodoc_type_aliases doesn't work for the instance attrs
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 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

1 participant