Skip to content

Commit 363f1be

Browse files
committed
convert doc decorator back to function
1 parent 21fa045 commit 363f1be

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pandas/util/_decorators.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]:
245245
return decorate
246246

247247

248-
class doc:
248+
def doc(*args: Union[str, Callable], **kwargs: str) -> Callable[[F], F]:
249249
"""
250250
A decorator take docstring templates, concatenate them and perform string
251251
substitution on it.
@@ -265,17 +265,13 @@ class doc:
265265
The string which would be used to format docstring template.
266266
"""
267267

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:
273269
# collecting docstring and docstring templates
274270
docstring_components: List[Union[str, Callable]] = []
275271
if func.__doc__:
276272
docstring_components.append(dedent(func.__doc__))
277273

278-
for appender in self.appenders:
274+
for appender in args:
279275
if hasattr(appender, "_docstring_components"):
280276
docstring_components.extend(
281277
appender._docstring_components # type: ignore
@@ -286,7 +282,7 @@ def __call__(self, func: F) -> F:
286282
# formatting templates and concatenating docstring
287283
func.__doc__ = "".join(
288284
[
289-
component.format(**self.substitution)
285+
component.format(**kwargs)
290286
if isinstance(component, str)
291287
else dedent(component.__doc__ or "")
292288
for component in docstring_components
@@ -296,6 +292,8 @@ def __call__(self, func: F) -> F:
296292
func._docstring_components = docstring_components # type: ignore
297293
return func
298294

295+
return decorator
296+
299297

300298
# Substitution and Appender are derived from matplotlib.docstring (1.1.0)
301299
# module https://matplotlib.org/users/license.html

0 commit comments

Comments
 (0)