]> granicus.if.org Git - python/commitdiff
Issue #29338: The help of a builtin or extension class now includes the
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 23 Jan 2017 10:37:00 +0000 (12:37 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 23 Jan 2017 10:37:00 +0000 (12:37 +0200)
constructor signature if __text_signature__ is provided for the class.

Lib/pydoc.py
Misc/NEWS

index 39db3915dc2cac938153ce5fce56fb0b82d17e93..f0c7cfce2e4f0713f0a192b2326bd367049c58d1 100644 (file)
@@ -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:
index 5d1e9c1117dfb25c95177e6c44c6e7ceb9bc5837..1f3bd79b8c900b3d1d876fbb65113106421e258b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -215,6 +215,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #29338: The help of a builtin or extension class now includes the
+  constructor signature if __text_signature__ is provided for the class.
+
 - Issue #29335: Fix subprocess.Popen.wait() when the child process has
   exited to a stopped instead of terminated state (ex: when under ptrace).