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

Annotations on "next generation" attrs classes not supported by autodoc #9752

Closed
jwodder opened this issue Oct 18, 2021 · 1 comment
Closed

Comments

@jwodder
Copy link

jwodder commented Oct 18, 2021

Describe the bug

Version 20.1.0 of attrs introduced a new "next generation" API that uses attr.define and attr.field instead of attr.s and attr.ib. Unfortunately, autodoc does not treat this new API the same way as the old one; in particular, type annotations on attributes are not shown when using the new API.

How to Reproduce

$ git clone https://github.com/jwodder/sphinx-attrs-bug-20211018
$ cd sphinx-attrs-bug-20211018
$ tox -e docs
$ open docs/_build/html/index.html

Open docs/_build/html/index.html in a browser and observe that the @attr.s-using class has its attributes' type annotations shown, while the @attr.define-using one does not. Conversely, the @attr.define class has a constructor signature shown, while the @attr.s one does not.

Expected behavior

The rendered documentation for the @attr.s class and the @attr.define class should be the same, particularly in that the attributes of the @attr.define class should have their type annotations shown.

Your project

https://github.com/jwodder/sphinx-attrs-bug-20211018

Screenshots

Screen Shot 2021-10-18 at 19 21 32

OS

macOS

Python version

3.9.7

Sphinx version

4.2.0

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

@tk0miya
Copy link
Member

tk0miya commented Oct 23, 2021

Note: It seems @attr.define uses __slots__ to generate attributes:

root@91e94d32e5d8:/sphinx-attrs-bug-20211018/docs# python
Python 3.9.7 (default, Sep  3 2021, 02:02:37)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinx_attrs
>>> sphinx_attrs.Foo.__slots__
('bar', 'baz', 'quux', '__weakref__')

@tk0miya tk0miya added this to the 4.3.0 milestone Oct 23, 2021
tk0miya added a commit that referenced this issue Oct 26, 2021
Fix #9752: autodoc: Failed to detect type annotation for slots attribute
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 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

2 participants