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: Handle multiple inheritance correctly #13136

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

pholica
Copy link
Contributor

@pholica pholica commented Nov 15, 2024

Subject: Handle multiple inheritance correctly in autodoc

Feature or Bugfix

  • 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:

  • foo_myclass
  • foo_parent2

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

The previous code went through mro sequentially not treating it
as a tree, which is needed in case of multiple inheritance.
Take following example:
```python
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:
 * foo_myclass
 * foo_parent2

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).
@pholica
Copy link
Contributor Author

pholica commented Nov 15, 2024

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.

@AA-Turner AA-Turner changed the title Handle multiple inheritance correctly in autodoc autodoc: Handle multiple inheritance correctly Feb 3, 2025
@AA-Turner AA-Turner merged commit 766900e into sphinx-doc:master Feb 3, 2025
23 checks passed
@AA-Turner AA-Turner added this to the 8.2.0 milestone Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants