Skip to content

Commit db7d517

Browse files
committed
Handle wrapped functions and class methods in pipesegment docstrings too
1 parent 5d1e208 commit db7d517

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

core/python/modconstruct.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,40 @@ def __doc__(self):
9494
doclines = []
9595
class PotemkinPipe(object):
9696
def Add(self, thing, *args, **kwargs):
97-
if hasattr(thing, '__wrapped__'):
98-
modname = thing.__wrapped__.__module__
97+
if hasattr(thing, "__wrapped__"):
98+
thing = thing.__wrapped__
99+
if hasattr(thing, "__self__"):
100+
cls = thing.__self__.__class__
101+
modname = "%s.%s" % (cls.__module__, cls.__name__)
99102
else:
100103
modname = thing.__module__
101-
doc = 'pipe.Add(%s.%s' % (modname, thing.__name__)
104+
if hasattr(thing, "__name__"):
105+
callname = thing.__name__
106+
elif hasattr(thing, "__class__"):
107+
callname = thing.__class__.__name__
108+
else:
109+
raise RuntimeError("Cannot establish name of pipeline module")
110+
docargs = ['%s.%s' % (modname, callname)]
102111
for arg in args:
103-
doc += ', %s' % repr(arg)
112+
docargs.append(repr(arg))
104113
for arg in kwargs:
105114
# remove object hashes
106115
s = re.sub('<(.*) at (.*)>', '<\\1>', repr(kwargs[arg]))
107-
doc += ', %s=%s' % (arg, s)
108-
doc += ')'
109-
doclines.append(doc)
116+
docargs.append('%s=%s' % (arg, s))
117+
docstart = "pipe.Add("
118+
docend = ")"
119+
docargstr = ", ".join(docargs)
120+
# simple line wrapping
121+
doc = "%s%s%s" % (docstart, docargstr, docend)
122+
if len(doc) <= 88:
123+
doclines.append(doc)
124+
return
125+
doclines.append(docstart)
126+
if len(docargstr) <= 84:
127+
doclines.append(" " + docargstr)
128+
else:
129+
doclines.extend([" %s," % a for a in docargs])
130+
doclines.append(docend)
110131
fake = PotemkinPipe()
111132
try:
112133
self.func(fake)

0 commit comments

Comments
 (0)