@@ -245,7 +245,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
245
245
return decorate
246
246
247
247
248
- class doc :
248
+ def doc ( * args : Union [ str , Callable ], ** kwargs : str ) -> Callable [[ F ], F ] :
249
249
"""
250
250
A decorator take docstring templates, concatenate them and perform string
251
251
substitution on it.
@@ -265,17 +265,13 @@ class doc:
265
265
The string which would be used to format docstring template.
266
266
"""
267
267
268
- def __init__ (self , * args : Union [str , Callable ], ** kwargs : str ) -> None :
269
- self .appenders = args
270
- self .substitution = kwargs
271
-
272
- def __call__ (self , func : F ) -> F :
268
+ def decorator (func : F ) -> F :
273
269
# collecting docstring and docstring templates
274
270
docstring_components : List [Union [str , Callable ]] = []
275
271
if func .__doc__ :
276
272
docstring_components .append (dedent (func .__doc__ ))
277
273
278
- for appender in self . appenders :
274
+ for appender in args :
279
275
if hasattr (appender , "_docstring_components" ):
280
276
docstring_components .extend (
281
277
appender ._docstring_components # type: ignore
@@ -286,7 +282,7 @@ def __call__(self, func: F) -> F:
286
282
# formatting templates and concatenating docstring
287
283
func .__doc__ = "" .join (
288
284
[
289
- component .format (** self . substitution )
285
+ component .format (** kwargs )
290
286
if isinstance (component , str )
291
287
else dedent (component .__doc__ or "" )
292
288
for component in docstring_components
@@ -296,6 +292,8 @@ def __call__(self, func: F) -> F:
296
292
func ._docstring_components = docstring_components # type: ignore
297
293
return func
298
294
295
+ return decorator
296
+
299
297
300
298
# Substitution and Appender are derived from matplotlib.docstring (1.1.0)
301
299
# module https://matplotlib.org/users/license.html
0 commit comments