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.
This commit is contained in:
Sanyam Khurana 2018-10-21 00:22:02 -07:00 committed by Nick Coghlan
parent d31e7730cd
commit a323cdcb33
3 changed files with 140 additions and 0 deletions

View file

@ -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):