sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.61k stars 2.13k forks source link

Handle multiple inheritance correctly in autodoc #13136

Open pholica opened 6 days ago

pholica commented 6 days ago

Subject: Handle multiple inheritance correctly in autodoc

Feature or Bugfix

Purpose

The previous code went through mro sequentially not treating it as a tree, which is needed in case of multiple inheritance. Take following example:

class MyClass(Parent1, Parent2):
    foo_myclass=None

class Parent1(GrandParent1):
    foo_parent1=None

class GrantParent1:
    foo_grandparent1=None

class Parent2:
    foo_parent2

When :show-inheritance: Parent1 is used, only following attributes should be shown:

The foo_parent2 was previously not considered as the MRO matched Parent1 before Parent2 but didn't check if it was really defined there.

The new code checks if the attribude is defined either directly in the ignored class or in one of it's parents (that's why the issubclass in reversed order is used).

Detail

Relates

pholica commented 6 days ago

I'm really not sure if this is the proper way how to approach the line-too-long as this is also not nice formatting, but I don't know the conventions. Also I'm a fan on list comprehensions, but if you don't like it feel free to change it or let me know which other approach you'd like to take. Thanks.