Skip to content

Commit

Permalink
Try suppressing external inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
alanakbik committed Dec 7, 2024
1 parent 9555879 commit 3b2152d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# -- Project information -----------------------------------------------------
from sphinx_github_style import get_linkcode_resolve
from torch.nn import Module

version = "0.14.0"
release = "0.14.0"
Expand Down Expand Up @@ -143,3 +144,36 @@ def linkcode_resolve(*args):
smv_prefer_remote_refs = False

html_favicon = "_static/favicon.ico"

import types


def skip_inherited_methods_from_base_class(app, what, name, obj, skip, options):
"""
This function is triggered by Sphinx to determine whether to include or
skip a specific member in the documentation. We use this to suppress inherited
methods from a particular base class.
"""
# Check if the object is a method (or function)
if what == "method" or what == "function":
# Check if the object is a method of a class
if isinstance(obj, (types.FunctionType, types.MethodType)):
# Get the class that owns the method
if hasattr(obj, "__self__"):
cls = obj.__self__.__class__ # The class of the method
else:
return skip # Skip non-methods

# Check if the class is inheriting from BaseClassA (the base class to exclude)
if issubclass(cls, Module):
return True # Skip methods inherited from BaseClassA

return skip # No changes for other cases


def setup(app):
"""
Connect the skip function to the `autodoc-skip-member` event.
This will call the function each time Sphinx decides whether to include a member.
"""
app.connect("autodoc-skip-member", skip_inherited_methods_from_base_class)

0 comments on commit 3b2152d

Please sign in to comment.