Skip to content

Commit 7e08197

Browse files
authored
Merge pull request #42 from rsokl/autoformat
run isort and black on everything
2 parents 072d240 + 2802388 commit 7e08197

File tree

11 files changed

+516
-451
lines changed

11 files changed

+516
-451
lines changed

src/custom_inherit/__init__.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
from abc import ABCMeta as _ABCMeta
44

5+
from . import _style_store
56
from ._decorator_base import DocInheritDecorator as _DocInheritDecorator
67
from ._metaclass_base import DocInheritorBase as _DocInheritorBase
7-
from . import _style_store
88
from ._style_store import (
9-
google, numpy, numpy_napoleon, parent, reST,
10-
google_with_merge, numpy_napoleon_with_merge, numpy_with_merge
9+
google,
10+
google_with_merge,
11+
numpy,
12+
numpy_napoleon,
13+
numpy_napoleon_with_merge,
14+
numpy_with_merge,
15+
parent,
16+
reST,
1117
)
1218
from ._version import get_versions
1319

@@ -31,11 +37,11 @@ def _check_style_function(style_func):
3137

3238

3339
class _Store(object):
34-
""" A dictionary-like object that stores the styles available for the doc-inheritance metaclass and decorator,
35-
respectively.
40+
"""A dictionary-like object that stores the styles available for the doc-inheritance metaclass and decorator,
41+
respectively.
3642
37-
Only callable objects with the signature: f(Optional[str], Optional[str]) -> Optional[str]
38-
can be stored. If f is a valid callable, then _Store()[f] -> f."""
43+
Only callable objects with the signature: f(Optional[str], Optional[str]) -> Optional[str]
44+
can be stored. If f is a valid callable, then _Store()[f] -> f."""
3945

4046
def __init__(self, *args, **kwargs):
4147
self._store = dict()
@@ -50,7 +56,7 @@ def __str__(self):
5056
return "\n".join((out_str, styles))
5157

5258
def __setitem__(self, style_name, style_func):
53-
""" Make available a new function for merging a 'parent' and 'child' docstring.
59+
"""Make available a new function for merging a 'parent' and 'child' docstring.
5460
5561
Parameters
5662
----------
@@ -68,7 +74,7 @@ def __setitem__(self, style_name, style_func):
6874
self._store[style_name] = style_func
6975

7076
def __getitem__(self, item):
71-
""" Given a valid style-ID, retrieve a stored style. If a valid function (callable) is
77+
"""Given a valid style-ID, retrieve a stored style. If a valid function (callable) is
7278
supplied, return it in place.
7379
7480
Parameters
@@ -91,8 +97,8 @@ def keys(self):
9197
return self._store.keys()
9298

9399
def pop(self, *args):
94-
""" D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
95-
If key is not found, d is returned if given, otherwise KeyError is raised. """
100+
"""D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
101+
If key is not found, d is returned if given, otherwise KeyError is raised."""
96102
if len(args) < 3:
97103
return self._store.pop(*args)
98104
else:
@@ -101,7 +107,7 @@ def pop(self, *args):
101107
)
102108

103109
def update(self, *args, **kwargs):
104-
""" D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
110+
"""D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
105111
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]"""
106112
if len(args) > 1:
107113
raise TypeError("update expected at most 1 arguments, got %d" % len(args))
@@ -117,11 +123,12 @@ def items(self):
117123
""" D.items() -> a set-like object providing a view on D's items"""
118124
return self._store.items()
119125

126+
120127
store = _Store([(key, getattr(_style_store, key)) for key in _style_store.__all__])
121128

122129

123130
def add_style(style_name, style_func):
124-
""" Make available a new function for merging a 'parent' and 'child' docstring.
131+
"""Make available a new function for merging a 'parent' and 'child' docstring.
125132
126133
Parameters
127134
----------
@@ -133,7 +140,7 @@ def add_style(style_name, style_func):
133140

134141

135142
def remove_style(style):
136-
""" Remove the specified style from the style store.
143+
"""Remove the specified style from the style store.
137144
138145
Parameters
139146
----------
@@ -143,8 +150,10 @@ def remove_style(style):
143150
store.pop(style)
144151

145152

146-
def DocInheritMeta(style="parent", abstract_base_class=False, include_special_methods=False):
147-
""" A metaclass that merges the respective docstrings of a parent class and of its child, along with their
153+
def DocInheritMeta(
154+
style="parent", abstract_base_class=False, include_special_methods=False
155+
):
156+
"""A metaclass that merges the respective docstrings of a parent class and of its child, along with their
148157
properties, methods (including classmethod, staticmethod, decorated methods).
149158
150159
Parameters
@@ -169,7 +178,11 @@ def DocInheritMeta(style="parent", abstract_base_class=False, include_special_me
169178
custom_inherit.DocInheritorBase"""
170179

171180
merge_func = store[style]
172-
metaclass = type(_DocInheritorBase.__name__, _DocInheritorBase.__bases__, dict(_DocInheritorBase.__dict__))
181+
metaclass = type(
182+
_DocInheritorBase.__name__,
183+
_DocInheritorBase.__bases__,
184+
dict(_DocInheritorBase.__dict__),
185+
)
173186
metaclass.include_special_methods = include_special_methods
174187
metaclass.class_doc_inherit = staticmethod(merge_func)
175188
metaclass.attr_doc_inherit = staticmethod(merge_func)
@@ -182,7 +195,7 @@ def DocInheritMeta(style="parent", abstract_base_class=False, include_special_me
182195

183196

184197
def doc_inherit(parent, style="parent"):
185-
""" Returns a function/method decorator that, given `parent`, updates the docstring of the decorated
198+
"""Returns a function/method decorator that, given `parent`, updates the docstring of the decorated
186199
function/method based on the specified style and the corresponding attribute of `parent`.
187200
188201
Parameters

src/custom_inherit/_decorator_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class DocInheritDecorator(object):
12-
""" A decorator that merges provided parent docstring with the docstring of the decorated
12+
"""A decorator that merges provided parent docstring with the docstring of the decorated
1313
function/method/property.
1414
1515
Methods
@@ -50,7 +50,7 @@ def __call__(self, func):
5050

5151
@staticmethod
5252
def doc_merger(prnt_attr_doc, child_doc):
53-
""" Merges the parent and child docstrings into a single docstring.
53+
"""Merges the parent and child docstrings into a single docstring.
5454
5555
Parameters
5656
----------

src/custom_inherit/_doc_parse_tools/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22

3-
from .napoleon_parse_tools import (merge_google_napoleon_docs,
4-
merge_numpy_napoleon_docs)
3+
from .napoleon_parse_tools import merge_google_napoleon_docs, merge_numpy_napoleon_docs
54
from .numpy_parse_tools import merge_numpy_docs
65
from .rest_parse_tools import merge_rest_docs
76

src/custom_inherit/_doc_parse_tools/napoleon_parse_tools.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def parse_napoleon_doc(doc, style):
23-
""" Extract the text from the various sections of a numpy-formatted docstring.
23+
"""Extract the text from the various sections of a numpy-formatted docstring.
2424
2525
Parameters
2626
----------
@@ -96,7 +96,7 @@ def parse_napoleon_doc(doc, style):
9696

9797

9898
def merge_section(key, prnt_sec, child_sec, style, merge_within_sections=False):
99-
""" Synthesize a output napoleon docstring section.
99+
"""Synthesize a output napoleon docstring section.
100100
101101
Parameters
102102
----------
@@ -133,7 +133,7 @@ def merge_section(key, prnt_sec, child_sec, style, merge_within_sections=False):
133133

134134

135135
def merge_all_sections(prnt_sctns, child_sctns, style, merge_within_sections=False):
136-
""" Merge the doc-sections of the parent's and child's attribute into a single docstring.
136+
"""Merge the doc-sections of the parent's and child's attribute into a single docstring.
137137
138138
Parameters
139139
----------
@@ -158,15 +158,17 @@ def merge_all_sections(prnt_sctns, child_sctns, style, merge_within_sections=Fal
158158
prnt_sctns[key],
159159
child_sctns[key],
160160
style,
161-
merge_within_sections=merge_within_sections
161+
merge_within_sections=merge_within_sections,
162162
)
163163
if sect is not None:
164164
doc.append(sect)
165165
return "\n\n".join(doc) if doc else None
166166

167167

168-
def merge_numpy_napoleon_docs(prnt_doc=None, child_doc=None, merge_within_sections=False):
169-
""" Merge two numpy-style docstrings into a single docstring, according to napoleon docstring sections.
168+
def merge_numpy_napoleon_docs(
169+
prnt_doc=None, child_doc=None, merge_within_sections=False
170+
):
171+
"""Merge two numpy-style docstrings into a single docstring, according to napoleon docstring sections.
170172
171173
Given the numpy-style docstrings from a parent and child's attributes, merge the docstring
172174
sections such that the child's section is used, wherever present, otherwise the parent's
@@ -187,18 +189,20 @@ def merge_numpy_napoleon_docs(prnt_doc=None, child_doc=None, merge_within_sectio
187189
Returns
188190
-------
189191
Union[str, None]
190-
The merged docstring. """
192+
The merged docstring."""
191193
style = "numpy"
192194
return merge_all_sections(
193195
parse_napoleon_doc(prnt_doc, style),
194196
parse_napoleon_doc(child_doc, style),
195197
style,
196-
merge_within_sections=merge_within_sections
198+
merge_within_sections=merge_within_sections,
197199
)
198200

199201

200-
def merge_google_napoleon_docs(prnt_doc=None, child_doc=None, merge_within_sections=False):
201-
""" Merge two google-style docstrings into a single docstring, according to napoleon docstring sections.
202+
def merge_google_napoleon_docs(
203+
prnt_doc=None, child_doc=None, merge_within_sections=False
204+
):
205+
"""Merge two google-style docstrings into a single docstring, according to napoleon docstring sections.
202206
203207
Given the google-style docstrings from a parent and child's attributes, merge the docstring
204208
sections such that the child's section is used, wherever present, otherwise the parent's
@@ -219,11 +223,11 @@ def merge_google_napoleon_docs(prnt_doc=None, child_doc=None, merge_within_secti
219223
Returns
220224
-------
221225
Union[str, None]
222-
The merged docstring. """
226+
The merged docstring."""
223227
style = "google"
224228
return merge_all_sections(
225229
parse_napoleon_doc(prnt_doc, style),
226230
parse_napoleon_doc(child_doc, style),
227231
style,
228-
merge_within_sections=merge_within_sections
232+
merge_within_sections=merge_within_sections,
229233
)

src/custom_inherit/_doc_parse_tools/numpy_parse_tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def parse_numpy_doc(doc):
12-
""" Extract the text from the various sections of a numpy-formatted docstring.
12+
"""Extract the text from the various sections of a numpy-formatted docstring.
1313
1414
Parameters
1515
----------
@@ -69,7 +69,7 @@ def parse_numpy_doc(doc):
6969

7070

7171
def merge_section(key, prnt_sec, child_sec, merge_within_sections=False):
72-
""" Synthesize a output numpy docstring section.
72+
"""Synthesize a output numpy docstring section.
7373
7474
Parameters
7575
----------
@@ -101,7 +101,7 @@ def merge_section(key, prnt_sec, child_sec, merge_within_sections=False):
101101

102102

103103
def merge_all_sections(prnt_sctns, child_sctns, merge_within_sections=False):
104-
""" Merge the doc-sections of the parent's and child's attribute into a single docstring.
104+
"""Merge the doc-sections of the parent's and child's attribute into a single docstring.
105105
106106
Parameters
107107
----------
@@ -125,15 +125,15 @@ def merge_all_sections(prnt_sctns, child_sctns, merge_within_sections=False):
125125
key,
126126
prnt_sctns[key],
127127
child_sctns[key],
128-
merge_within_sections=merge_within_sections
128+
merge_within_sections=merge_within_sections,
129129
)
130130
if sect is not None:
131131
doc.append(sect)
132132
return "\n\n".join(doc) if doc else None
133133

134134

135135
def merge_numpy_docs(prnt_doc=None, child_doc=None, merge_within_sections=False):
136-
""" Merge two numpy-style docstrings into a single docstring.
136+
"""Merge two numpy-style docstrings into a single docstring.
137137
138138
Given the numpy-style docstrings from a parent and child's attributes, merge the docstring
139139
sections such that the child's section is used, wherever present, otherwise the parent's
@@ -153,9 +153,9 @@ def merge_numpy_docs(prnt_doc=None, child_doc=None, merge_within_sections=False)
153153
-------
154154
Union[str, None]
155155
The merged docstring.
156-
"""
156+
"""
157157
return merge_all_sections(
158158
parse_numpy_doc(prnt_doc),
159159
parse_numpy_doc(child_doc),
160-
merge_within_sections=merge_within_sections
160+
merge_within_sections=merge_within_sections,
161161
)

src/custom_inherit/_doc_parse_tools/rest_parse_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ def is_delimiter(line):
1313

1414

1515
def parse_rest_doc(doc):
16-
""" Extract the headers, delimiters, and text from reST-formatted docstrings.
16+
"""Extract the headers, delimiters, and text from reST-formatted docstrings.
1717
1818
Parameters
1919
----------
2020
doc: Union[str, None]
2121
2222
Returns
2323
-------
24-
Dict[str, Section] """
24+
Dict[str, Section]"""
2525

2626
class Section(object):
2727
def __init__(self, header=None, body=None):

src/custom_inherit/_doc_parse_tools/section_items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""This module handles sections with items."""
22

3-
from collections import OrderedDict
43
import inspect
54
import re
5+
from collections import OrderedDict
66

77
try:
88
from textwrap import indent

0 commit comments

Comments
 (0)