Skip to content

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

@jwodder

Description

@jwodder

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions