Skip to content

Commit

Permalink
Merge branch 'master' into test/xdist
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored Feb 3, 2025
2 parents 5554f68 + 766900e commit 9c91771
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Bugs fixed
* #12975: Avoid rendering a trailing comma in C and C++ multi-line signatures.
* #13178: autodoc: Fix resolution for ``pathlib`` types.
Patch by Adam Turner.
* #13136: autodoc: Correctly handle multiple inheritance.
Patch by Pavel Holica

Testing
-------
Expand Down
11 changes: 10 additions & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,19 @@ def filter_members(

def is_filtered_inherited_member(name: str, obj: Any) -> bool:
inherited_members = self.options.inherited_members or set()
seen = set()

if inspect.isclass(self.object):
for cls in self.object.__mro__:
if cls.__name__ in inherited_members and cls != self.object:
if name in cls.__dict__:
seen.add(cls)
if (
cls.__name__ in inherited_members
and cls != self.object
and any(
issubclass(potential_child, cls) for potential_child in seen
)
):
# given member is a member of specified *super class*
return True
if name in cls.__dict__:
Expand Down
8 changes: 7 additions & 1 deletion tests/roots/test-ext-autodoc/target/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def inheritedstaticmeth(cls): # NoQA: PLW0211
"""Inherited static method."""


class Derived(Base):
class AnotherBase:
#: docstring
def another_inheritedmeth(self):
"""Another inherited function."""


class Derived(Base, AnotherBase):
def inheritedmeth(self):
# no docstring here
pass
Expand Down
1 change: 1 addition & 0 deletions tests/test_extensions/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ def test_autodoc_inherited_members(app):
}
actual = do_autodoc(app, 'class', 'target.inheritance.Derived', options)
assert list(filter(lambda l: 'method::' in l, actual)) == [
' .. py:method:: Derived.another_inheritedmeth()',
' .. py:method:: Derived.inheritedclassmeth()',
' .. py:method:: Derived.inheritedmeth()',
' .. py:method:: Derived.inheritedstaticmeth(cls)',
Expand Down
16 changes: 16 additions & 0 deletions tests/test_extensions/test_ext_autodoc_automodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def test_automodule_inherited_members(app):
'.. py:module:: target.inheritance',
'',
'',
'.. py:class:: AnotherBase()',
' :module: target.inheritance',
'',
'',
' .. py:method:: AnotherBase.another_inheritedmeth()',
' :module: target.inheritance',
'',
' Another inherited function.',
'',
'',
'.. py:class:: Base()',
' :module: target.inheritance',
'',
Expand Down Expand Up @@ -169,6 +179,12 @@ def test_automodule_inherited_members(app):
' :module: target.inheritance',
'',
'',
' .. py:method:: Derived.another_inheritedmeth()',
' :module: target.inheritance',
'',
' Another inherited function.',
'',
'',
' .. py:method:: Derived.inheritedmeth()',
' :module: target.inheritance',
'',
Expand Down
12 changes: 12 additions & 0 deletions tests/test_extensions/test_ext_autodoc_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ def test_autodoc_inherit_docstrings_for_inherited_members(app):
' :module: target.inheritance',
'',
'',
' .. py:method:: Derived.another_inheritedmeth()',
' :module: target.inheritance',
'',
' Another inherited function.',
'',
'',
' .. py:attribute:: Derived.inheritedattr',
' :module: target.inheritance',
' :value: None',
Expand Down Expand Up @@ -356,6 +362,12 @@ def test_autodoc_inherit_docstrings_for_inherited_members(app):
' :module: target.inheritance',
'',
'',
' .. py:method:: Derived.another_inheritedmeth()',
' :module: target.inheritance',
'',
' Another inherited function.',
'',
'',
' .. py:method:: Derived.inheritedclassmeth()',
' :module: target.inheritance',
' :classmethod:',
Expand Down

0 comments on commit 9c91771

Please sign in to comment.