Skip to content

Commit 2ace972

Browse files
authored
Merge pull request #143 from tetov/class-docstring-fix
Fixes for class docs
2 parents 788739f + 04d382b commit 2ace972

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/conf.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
import sphinx_compas_theme
66

7+
from sphinx.ext.napoleon.docstring import NumpyDocstring
8+
79
extensions = [
810
'sphinx.ext.autodoc',
911
'sphinx.ext.autosummary',
@@ -46,7 +48,6 @@
4648
# autodoc options
4749
autodoc_default_options = {
4850
'member-order': 'bysource',
49-
'special-members': '__init__',
5051
'exclude-members': '__weakref__',
5152
'undoc-members': True,
5253
'private-members': True,
@@ -93,3 +94,38 @@
9394
napoleon_use_param = False
9495
napoleon_use_rtype = False
9596

97+
# Parse Attributes and Class Attributes on Class docs same as parameters.
98+
# first, we define new methods for any new sections and add them to the class
99+
100+
101+
def parse_keys_section(self, section):
102+
return self._format_fields('Keys', self._consume_fields())
103+
104+
105+
NumpyDocstring._parse_keys_section = parse_keys_section
106+
107+
108+
def parse_attributes_section(self, section):
109+
return self._format_fields('Attributes', self._consume_fields())
110+
111+
112+
NumpyDocstring._parse_attributes_section = parse_attributes_section
113+
114+
115+
def parse_class_attributes_section(self, section):
116+
return self._format_fields('Class Attributes', self._consume_fields())
117+
118+
119+
NumpyDocstring._parse_class_attributes_section = parse_class_attributes_section
120+
121+
122+
# we now patch the parse method to guarantee that the the above methods are
123+
# assigned to the _section dict
124+
def patched_parse(self):
125+
self._sections['keys'] = self._parse_keys_section
126+
self._sections['class attributes'] = self._parse_class_attributes_section
127+
self._unpatched_parse()
128+
129+
130+
NumpyDocstring._unpatched_parse = NumpyDocstring._parse
131+
NumpyDocstring._parse = patched_parse

0 commit comments

Comments
 (0)