summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>2018-10-21 07:22:02 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-10-21 07:22:02 (GMT)
commita323cdcb33c8c856e5668acfb2c67ab5198672c4 (patch)
treea53d57bcb7b958f1517a59603e07c8c205cf6f6e /Lib/pydoc.py
parentd31e7730cd5d74efbd7320751dacd51d09cc415d (diff)
downloadcpython-a323cdcb33c8c856e5668acfb2c67ab5198672c4.zip
cpython-a323cdcb33c8c856e5668acfb2c67ab5198672c4.tar.gz
cpython-a323cdcb33c8c856e5668acfb2c67ab5198672c4.tar.bz2
bpo-8525: help() on a type now shows builtin subclasses (GH-5066)
For builtin types with builtin subclasses, help() on the type now shows up to 4 of the subclasses. This partially replaces the exception hierarchy information previously displayed in Python 2.7.
Diffstat (limited to 'Lib/pydoc.py')
-rw-r--r--Lib/pydoc.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 8a6b27b..3a46171 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1254,6 +1254,24 @@ location listed above.
push(' ' + makename(base))
push('')
+ # List the built-in subclasses, if any:
+ subclasses = sorted(
+ (str(cls.__name__) for cls in object.__subclasses__()
+ if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
+ key=str.lower
+ )
+ no_of_subclasses = len(subclasses)
+ MAX_SUBCLASSES_TO_DISPLAY = 4
+ if subclasses:
+ push("Built-in subclasses:")
+ for subclassname in subclasses[:MAX_SUBCLASSES_TO_DISPLAY]:
+ push(' ' + subclassname)
+ if no_of_subclasses > MAX_SUBCLASSES_TO_DISPLAY:
+ push(' ... and ' +
+ str(no_of_subclasses - MAX_SUBCLASSES_TO_DISPLAY) +
+ ' other subclasses')
+ push('')
+
# Cute little class to pump out a horizontal rule between sections.
class HorizontalRule:
def __init__(self):