summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-01-23 10:37:00 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-01-23 10:37:00 (GMT)
commitccb5f3cee9ebb5f20e33f31432a46579f8e9bf8e (patch)
treee870c66bd1e0fcb04ad1c8c3acf440e359c0bcd9 /Lib/pydoc.py
parent9fa4a120f0c8e52a8823cb4321020b8d4beedc00 (diff)
downloadcpython-ccb5f3cee9ebb5f20e33f31432a46579f8e9bf8e.zip
cpython-ccb5f3cee9ebb5f20e33f31432a46579f8e9bf8e.tar.gz
cpython-ccb5f3cee9ebb5f20e33f31432a46579f8e9bf8e.tar.bz2
Issue #29338: The help of a builtin or extension class now includes the
constructor signature if __text_signature__ is provided for the class.
Diffstat (limited to 'Lib/pydoc.py')
-rw-r--r--Lib/pydoc.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 39db391..f0c7cfc 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -909,7 +909,21 @@ class HTMLDoc(Doc):
for base in bases:
parents.append(self.classlink(base, object.__module__))
title = title + '(%s)' % ', '.join(parents)
- doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
+
+ decl = ''
+ try:
+ signature = inspect.signature(object)
+ except (ValueError, TypeError):
+ signature = None
+ if signature:
+ argspec = str(signature)
+ if argspec:
+ decl = name + self.escape(argspec) + '\n\n'
+
+ doc = getdoc(object)
+ if decl:
+ doc = decl + (doc or '')
+ doc = self.markup(doc, self.preformat, funcs, classes, mdict)
doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc
return self.section(title, '#000000', '#ffc8d8', contents, 3, doc)
@@ -1213,10 +1227,22 @@ location listed above.
parents = map(makename, bases)
title = title + '(%s)' % ', '.join(parents)
- doc = getdoc(object)
- contents = doc and [doc + '\n'] or []
+ contents = []
push = contents.append
+ try:
+ signature = inspect.signature(object)
+ except (ValueError, TypeError):
+ signature = None
+ if signature:
+ argspec = str(signature)
+ if argspec:
+ push(name + argspec + '\n')
+
+ doc = getdoc(object)
+ if doc:
+ push(doc + '\n')
+
# List the mro, if non-trivial.
mro = deque(inspect.getmro(object))
if len(mro) > 2: