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

Handle multiple inheritance correctly in autodoc #13136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pholica
Copy link

@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
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.

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.

2 participants