You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-14Lines changed: 39 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -53,10 +53,10 @@ class Parent(metaclass=DocInheritMeta(style="numpy")):
53
53
----------
54
54
x: int
55
55
blah-x
56
-
56
+
57
57
y: Optional[int]
58
58
blah-y
59
-
59
+
60
60
Raises
61
61
------
62
62
NotImplementedError"""
@@ -85,7 +85,7 @@ Because we specified `style="numpy"` in `DocInheritMeta`, the inherited docstrin
85
85
----------
86
86
x: int
87
87
blah-x
88
-
88
+
89
89
y: Optional[int]
90
90
blah-y
91
91
@@ -146,44 +146,69 @@ class Parent(metaclass=DocInheritMeta(style="numpy", abstract_base_class=True)):
146
146
147
147
For the "numpy", "google", and "napoleon_numpy" inheritance styles, one then only needs to specify the "Returns" or "Yields" section in the derived class' attribute docstring for it to have a fully-detailed docstring.
148
148
149
+
Another option is to be able to decide whether to include all special methods, meaning methods that start and
150
+
end by "__" such as "__init__" method, or not in the doctstring inheritance process. Such an option can be pass
151
+
to the `DocInheritMeta` metaclass constructor:
152
+
153
+
```python
154
+
# Each child class will also merge the special methods' docstring of its parent class
Utilize a built-in style by specifying any of the following names (as a string), wherever the `style` parameter is to be specified. The built-in styles are:
152
164
153
165
-`"parent"`: Wherever the docstring for a child-class' attribute (or for the class itself) is
154
166
`None`, inherit the corresponding docstring from the parent. (Deprecated in Python 3.5)
from the parent and child are merged gracefully with nice formatting. The child's docstring sections take precedence
170
+
in the case of overlap.
171
+
172
+
-`"numpy_with_merge"`: Behaves identically to the "numpy" style, but also merges sections that overlap,
173
+
instead of only keeping the child's section. All sections are concerned except sections "Short Summary",
174
+
"Extended Summary", "Deprecation Warning" and "Examples" for which the "numpy" style behaviour applies.
159
175
160
176
-`"google"`: Google-styled docstrings from the parent and child are merged gracefully
161
177
with nice formatting. The child's docstring sections take precedence in the case of overlap.
162
178
This adheres to the [napoleon specification for the Google style](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html#example-google-style-python-docstrings).
163
179
180
+
-`"google_with_merge"`: Behaves identically to the "google" style, but also merges sections that overlap,
181
+
instead of only keeping the child's section. All sections are concerned except sections "Short Summary",
182
+
"Example" and "Examples" (or coresponding aliases) for which the 'google' style applies.
183
+
164
184
-`"numpy_napoleon"`: NumPy-styled docstrings from the parent and child are merged gracefully
165
185
with nice formatting. The child's docstring sections take precedence in the case of overlap.
166
186
This adheres to the [napoleon specification for the NumPy style](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html#example-numpy).
167
187
188
+
-`"numpy_napoleon_with_merge"`: Behaves identically to the 'numpy_napoleon' style, but also merges sections
189
+
that overlap, instead of only keeping the child's section. All sections are concerned except sections
190
+
"Short Summary", "Example" and "Examples" (or coresponding aliases) for which the 'numpy_napoleon' style
191
+
behaviour applies.
192
+
168
193
-`"reST"`: reST-styled docstrings from the parent and child are merged gracefully
169
-
with nice formatting. Docstring sections are specified by
194
+
with nice formatting. Docstring sections are specified by
The child's docstring sections take precedence in the case of overlap.
172
197
173
-
For the `numpy`, `numpy_napoleon`, and`google` styles, if the parent's docstring contains a "Raises" section and the child's docstring implements a "Returns" or a "Yields" section instead, then the "Raises" section is not included in the resulting docstring. This is to accomodate for the relatively common use case in which an abstract method/property raises `NotImplementedError`. Child classes that implement this method/property clearly will not raise this. Of course, any "Raises" section that is explicitly included in the child's docstring will appear in the resulting docstring.
198
+
For the `numpy`, `numpy_with_merge`, `numpy_napoleon`, `numpy_napoleon_with_merge`,`google` and `google_with_merge` styles, if the parent's docstring contains a "Raises" section and the child's docstring implements a "Returns" or a "Yields" section instead, then the "Raises" section is not included in the resulting docstring. This is to accomodate for the relatively common use case in which an abstract method/property raises `NotImplementedError`. Child classes that implement this method/property clearly will not raise this. Of course, any "Raises" section that is explicitly included in the child's docstring will appear in the resulting docstring.
174
199
175
200
Detailed documentation and example cases for the default styles can be found [here](https://github.com/meowklaski/custom_inherit/blob/master/custom_inherit/_style_store.py)
176
201
177
202
## Making New Inheritance Styles
178
-
Implementing your inheritance style is simple.
203
+
Implementing your inheritance style is simple.
179
204
180
205
- Provide an inheritance style on the fly wherever a style parameter is specified:
181
206
- Supply any function of the form: `func(prnt_doc: str, child_doc: str) -> str`
182
207
183
208
- Log an inheritance style, and refer to it by name wherever a style parameter is specified, using either:
0 commit comments