Skip to content

Commit 667daa7

Browse files
committed
feat: add ExtendMethodDoc for extending method docstrings
1 parent 0c94f30 commit 667daa7

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

pins/boards.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .meta import Meta, MetaRaw, MetaFactory
1616
from .errors import PinsError
1717
from .drivers import load_data, save_data, default_title
18-
from .utils import inform
18+
from .utils import inform, ExtendMethodDoc
1919
from .config import get_allow_rsc_short_name
2020

2121

@@ -732,7 +732,15 @@ def pin_list(self):
732732
names = [f"{cont['owner_username']}/{cont['name']}" for cont in results]
733733
return names
734734

735-
def pin_write(self, *args, **kwargs):
735+
@ExtendMethodDoc
736+
def pin_write(self, *args, access_type=None, **kwargs):
737+
"""Write a pin.
738+
739+
Extends parent method in the following ways:
740+
741+
* Modifies content item to include any title and description changes.
742+
* Adds access_type argument to specify who can see content. Defaults to "acl".
743+
"""
736744

737745
# run parent function ---
738746

@@ -757,6 +765,7 @@ def pin_write(self, *args, **kwargs):
757765

758766
return meta
759767

768+
@ExtendMethodDoc
760769
def pin_search(self, search=None, as_df=True):
761770
from pins.rsconnect.api import RsConnectApiRequestError
762771

@@ -793,6 +802,7 @@ def pin_search(self, search=None, as_df=True):
793802

794803
return res
795804

805+
@ExtendMethodDoc
796806
def pin_version_delete(self, *args, **kwargs):
797807
from pins.rsconnect.api import RsConnectApiRequestError
798808

@@ -804,6 +814,7 @@ def pin_version_delete(self, *args, **kwargs):
804814

805815
raise PinsError("RStudio Connect cannot delete the latest pin version.")
806816

817+
@ExtendMethodDoc
807818
def pin_versions_prune(self, *args, **kwargs):
808819
sig = inspect.signature(super().pin_versions_prune)
809820
if sig.bind(*args, **kwargs).arguments.get("days") is not None:

pins/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,33 @@ def inform(log, msg):
99

1010
if not pins_options.quiet:
1111
print(msg, file=sys.stderr)
12+
13+
14+
class ExtendMethodDoc:
15+
template = """\
16+
{current_doc}
17+
18+
Parent method documentation:
19+
20+
{parent_doc}
21+
"""
22+
23+
def __init__(self, func):
24+
self.func = func
25+
26+
def __set_name__(self, owner, name):
27+
bound_parent_meth = getattr(super(owner, owner), name)
28+
29+
self._parent_doc = bound_parent_meth.__doc__
30+
self._orig_doc = self.func.__doc__
31+
32+
self.func.__doc__ = self.template.format(
33+
current_doc=self._orig_doc, parent_doc=self._parent_doc
34+
)
35+
self.__doc__ = self.func.__doc__
36+
37+
def __get__(self, obj, objtype=None):
38+
if obj is None:
39+
return self
40+
41+
return self.func

0 commit comments

Comments
 (0)