mirror of
https://github.com/python/cpython.git
synced 2025-08-25 19:24:42 +00:00
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:
parent
d31e7730cd
commit
a323cdcb33
3 changed files with 140 additions and 0 deletions
18
Lib/pydoc.py
18
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue