[Python-checkins] cpython: Issue #29338: The help of a builtin or extension class now includes the
serhiy.storchaka
python-checkins at python.org
Mon Jan 23 05:37:16 EST 2017
https://hg.python.org/cpython/rev/3d5dcdf26fab
changeset: 106285:3d5dcdf26fab
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Jan 23 12:37:00 2017 +0200
summary:
Issue #29338: The help of a builtin or extension class now includes the
constructor signature if __text_signature__ is provided for the class.
files:
Lib/pydoc.py | 32 +++++++++++++++++++++++++++++---
Misc/NEWS | 3 +++
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -909,7 +909,21 @@
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> </tt>' % doc
return self.section(title, '#000000', '#ffc8d8', contents, 3, doc)
@@ -1213,9 +1227,21 @@
parents = map(makename, bases)
title = title + '(%s)' % ', '.join(parents)
+ 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)
- contents = doc and [doc + '\n'] or []
- push = contents.append
+ if doc:
+ push(doc + '\n')
# List the mro, if non-trivial.
mro = deque(inspect.getmro(object))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -215,6 +215,9 @@
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).
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list