Message321651
Reviewing the builtins in 3.7, I get the following results for builtin objects that have defined subclasses immediately after interpreter startup:
=============
>>> for name, obj in vars(builtins).items():
... if isinstance(obj, type) and name in str(obj):
... subclasses = type(obj).__subclasses__(obj)
... if subclasses:
... print(f"{obj}: {len(subclasses)}")
...
<class 'classmethod'>: 1
<class 'dict'>: 1
<class 'property'>: 1
<class 'int'>: 1
<class 'object'>: 132
<class 'staticmethod'>: 1
<class 'tuple'>: 16
<class 'type'>: 1
<class 'BaseException'>: 4
<class 'Exception'>: 19
<class 'ImportError'>: 2
<class 'OSError'>: 13
<class 'RuntimeError'>: 3
<class 'NameError'>: 1
<class 'SyntaxError'>: 1
<class 'IndentationError'>: 1
<class 'LookupError'>: 3
<class 'ValueError'>: 2
<class 'UnicodeError'>: 3
<class 'ArithmeticError'>: 3
<class 'SystemError'>: 1
<class 'Warning'>: 10
<class 'ConnectionError'>: 4
=============
So rather than special-casing exceptions or builtins in general, my inclination would be to include a section that lists up to 4 subclasses inline, and then adds a "... and NNN additional subclasses" trailing when there are more than 4 (or when there are less than 4 subclasses with public names, but additional private subclasses).
So in a class like "int", for example, we'd see:
Currently imported subclasses:
bool
While in a class like OSError we'd see:
Currently imported subclasses:
BlockingIOError
ChildProcessError
ConnectionError
FileExistsError
... and 9 other subclasses
And in "help(object)" we'd see something like:
Currently imported subclasses:
async_generator
BaseException
builtin_function_or_method
bytearray
... and 215 other subclasses
The initial list of subclasses to show would be restricted to public builtins: `sorted((str(cls) for cls in object.__subclasses__() if not cls.__name__.startswith("_") and cls.__module__ == "builtins"), key=str.lower)`
If that gives less then four names, then the list of names would be expanded to subclasses with public names in public modules (i.e. neither __qualname__ nor __module__ starts with "_", neither of those contains "._", and qualname doesn't contain ".<locals>.").
The full count of currently imported subclasses would ignore whether the subclass names were public or not. |
|
Date |
User |
Action |
Args |
2018-07-14 12:44:18 | ncoghlan | set | recipients:
+ ncoghlan, georg.brandl, terry.reedy, belopolsky, ron_adam, eric.araujo, brian.curtin, robcliffe, henriquebastos, Rodolpho.Eckhardt, CuriousLearner |
2018-07-14 12:44:18 | ncoghlan | set | messageid: <1531572258.04.0.56676864532.issue8525@psf.upfronthosting.co.za> |
2018-07-14 12:44:18 | ncoghlan | link | issue8525 messages |
2018-07-14 12:44:17 | ncoghlan | create | |
|