Add smarts to autodoc_utils for inherited TypedDicts.

Review Request #14480 — Created June 27, 2025 and submitted

Information

beanbag-docutils
master

Reviewers

TypedDict inheritance is weird in a way that Sphinx can't deal with
easily. TypedDict isn't actually a class itself, and things which
inherit from it get flattened to inherit directly from dict and have a
variety of annotation-only properties for the data inside. Sphinx can
find any documentation attached to those properties, but when one
inherits from another, the documentation for any properties coming from
the parent class gets lost.

This change adds some custom documenter classes to detect when we have
inherited TypedDict members and to scan up the chain using
__orig_bases__ to find docs for inherited members.

This requires Python 3.11+ if using typing.TypedDict. It works for all
versions when using typing_extensions.TypedDict.

  • Built the RBTools documentation with this and saw that all of our new
    *Params definitions had documentation for all members, including ones
    inherited from parent classes.
  • Ran unit tests.
Summary ID
Add smarts to autodoc_utils for inherited TypedDicts.
`TypedDict` inheritance is weird in a way that Sphinx can't deal with easily. `TypedDict` isn't actually a class itself, and things which inherit from it get flattened to inherit directly from `dict` and have a variety of annotation-only properties for the data inside. Sphinx can find any documentation attached to those properties, but when one inherits from another, the documentation for any properties coming from the parent class gets lost. This change adds some custom documenter classes to detect when we have inherited TypedDict members and to scan up the chain using `__orig_bases__` to find docs for inherited members. This requires Python 3.11+ if using `typing.TypedDict`. It works for all versions when using `typing_extensions.TypedDict`. Testing Done: - Built the RBTools documentation with this and saw that all of our new `*Params` definitions had documentation for all members, including ones inherited from parent classes. - Ran unit tests.
e7869c4db5a0ffdc3b135721c9f997f5a0ac088f
Description From Last Updated

Let's make autodoc_utils a literal.

chipx86chipx86

Missing the ending __ on __orig_bases__

maubinmaubin

Should say "versions" or "an older version" here instead of just of "version"

maubinmaubin

"for" or "from"?

chipx86chipx86

This requires 3.9+. That might be fine but it'd be nice to keep this module a bit wider in terms …

chipx86chipx86

Should we use Sequence instead of list?

chipx86chipx86

We access self.object 3 times outside the loop and every iteration within the loop where there's a docstring. Let's pull …

chipx86chipx86

Should this be a Sequence?

chipx86chipx86

Missing a period.

chipx86chipx86

Missing a period.

chipx86chipx86

Can we use obj instead, so we're not stomping on object?

chipx86chipx86
maubin
  1. 
      
  2. Show all issues

    Missing the ending __ on __orig_bases__

  3. Show all issues

    Should say "versions" or "an older version" here instead of just of "version"

  4. 
      
chipx86
  1. 
      
  2. Show all issues

    Let's make autodoc_utils a literal.

  3. Show all issues

    "for" or "from"?

    1. for. The docstrings are coming from parent classes, not the inherited classes.

  4. Show all issues

    This requires 3.9+. That might be fine but it'd be nice to keep this module a bit wider in terms of Python compatibility so we can more easily continue to build docs for older (but still recent) products and deal with any issues that come up.

    Can we keep this a standard dict and move the typing into the annotation?

  5. Show all issues

    Should we use Sequence instead of list?

    1. This needs to match the parent class signature.

  6. Show all issues

    We access self.object 3 times outside the loop and every iteration within the loop where there's a docstring. Let's pull it out.

  7. Show all issues

    Should this be a Sequence?

  8. Show all issues

    Missing a period.

  9. Show all issues

    Missing a period.

  10. 
      
david
chipx86
  1. Looks good. One nit.

  2. Show all issues

    Can we use obj instead, so we're not stomping on object?

  3. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to master (fc1ce2d)