Skip to content

Commit 7a7ba4f

Browse files
committed
Split static methods to own section in autosummary
1 parent 4199c0c commit 7a7ba4f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

autoautosummary.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sphinx.ext.autosummary import Autosummary, get_documenter
1414
from sphinx.locale import __
1515
from sphinx.util import logging
16-
from sphinx.util.inspect import safe_getattr
16+
from sphinx.util.inspect import safe_getattr, isstaticmethod
1717

1818
# from sphinx.directives import directive
1919
logger = logging.getLogger(__name__)
@@ -43,6 +43,7 @@ class AutoAutoSummary(Autosummary):
4343

4444
option_spec = {
4545
"methods": directives.unchanged,
46+
"static_methods": directives.unchanged,
4647
"signals": directives.unchanged,
4748
"enums": directives.unchanged,
4849
"attributes": directives.unchanged,
@@ -76,7 +77,7 @@ def skip_member(doc, obj: Any, name: str, options, objtype: str) -> bool:
7677

7778
@staticmethod
7879
def get_members(
79-
doc, obj, typ, options, include_public: list | None = None, signal=False, enum=False
80+
doc, obj, typ, options, include_public: list | None = None, signal=False, enum=False, static=False
8081
):
8182
try:
8283
if not include_public:
@@ -97,7 +98,11 @@ def get_members(
9798
)
9899
if skipped is True:
99100
continue
100-
if typ == "attribute":
101+
if typ == "method":
102+
method_is_static = isstaticmethod(chobj, obj, name)
103+
if method_is_static != static:
104+
continue
105+
elif typ == "attribute":
101106
if signal and not isinstance(chobj, PyQt5.QtCore.pyqtSignal):
102107
continue
103108
if not signal and isinstance(chobj, PyQt5.QtCore.pyqtSignal):
@@ -138,6 +143,12 @@ def run(self):
138143
_, rubric_elems = self.get_members(
139144
self.state.document, c, "method", self.options, ["__init__"]
140145
)
146+
elif "static_methods" in self.options:
147+
rubric_title = "Static Methods"
148+
_, rubric_elems = self.get_members(self.state.document, c,
149+
"method",
150+
self.options,
151+
static=True)
141152
elif "enums" in self.options:
142153
rubric_title = "Enums"
143154
_, rubric_elems = self.get_members(

rst/qgis_pydoc_template.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Class: $CLASS
2424
:nosignatures:
2525
:exclude-members: $EXCLUDE_METHODS
2626

27+
.. autoautosummary:: qgis.$PACKAGE.$CLASS
28+
:static_methods:
29+
:nosignatures:
30+
:exclude-members: $EXCLUDE_METHODS
31+
2732
.. autoautosummary:: qgis.$PACKAGE.$CLASS
2833
:signals:
2934
:nosignatures:

0 commit comments

Comments
 (0)