3
3
import sys
4
4
import types
5
5
6
+
6
7
class Substitution (object ):
7
8
"""
8
9
A decorator to take a function's docstring and perform string
@@ -32,7 +33,8 @@ def some_function(x):
32
33
"%s %s wrote the Raven"
33
34
"""
34
35
def __init__ (self , * args , ** kwargs ):
35
- assert not (args and kwargs ), "Only positional or keyword args are allowed"
36
+ assert (not (args and kwargs ),
37
+ "Only positional or keyword args are allowed" )
36
38
self .params = args or kwargs
37
39
38
40
def __call__ (self , func ):
@@ -46,15 +48,16 @@ def update(self, *args, **kwargs):
46
48
@classmethod
47
49
def from_params (cls , params ):
48
50
"""
49
- In the case where the params is a mutable sequence (list or dictionary)
50
- and it may change before this class is called, one may explicitly use
51
- a reference to the params rather than using *args or **kwargs which will
52
- copy the values and not reference them.
51
+ In the case where the params is a mutable sequence (list or
52
+ dictionary) and it may change before this class is called, one may
53
+ explicitly use a reference to the params rather than using *args or
54
+ **kwargs which will copy the values and not reference them.
53
55
"""
54
56
result = cls ()
55
57
result .params = params
56
58
return result
57
59
60
+
58
61
class Appender (object ):
59
62
"""
60
63
A function decorator that will append an addendum to the docstring
@@ -83,11 +86,13 @@ def __call__(self, func):
83
86
func .__doc__ = func .__doc__ and '' .join (docitems )
84
87
return func
85
88
89
+
86
90
def dedent (func ):
87
91
"Dedent a docstring (if present)"
88
92
func .__doc__ = func .__doc__ and cbook .dedent (func .__doc__ )
89
93
return func
90
94
95
+
91
96
def copy (source ):
92
97
"Copy a docstring from another source function (if present)"
93
98
def do_copy (target ):
@@ -100,13 +105,15 @@ def do_copy(target):
100
105
# is reused throughout matplotlib
101
106
interpd = Substitution ()
102
107
108
+
103
109
def dedent_interpd (func ):
104
110
"""A special case of the interpd that first performs a dedent on
105
111
the incoming docstring"""
106
112
if isinstance (func , types .MethodType ) and sys .version_info [0 ] < 3 :
107
113
func = func .im_func
108
114
return interpd (dedent (func ))
109
115
116
+
110
117
def copy_dedent (source ):
111
118
"""A decorator that will copy the docstring from the source and
112
119
then dedent it"""
0 commit comments