[Python-ideas] Decide if `type.__subclasses__` is part of future Python or not
Joy Diamond
python.gem at gmail.com
Mon Oct 29 14:11:03 EDT 2018
Greetings,
Currently `type.__subclasses__` is not documented at docs.python.org (and
works in both python 2 & python 3).
I would like to keep `.__subclasses__` and have it documented at
docs.python.org.
Is there a reason it is not documented?
I realize the whole type system is going an overhaul, and the concept of
what is "subclass" of another class is a complicated issue.
See for example: https://github.com/python/typing/issues/135 which talks
about the complexity of deciding subclassing.
I think though, despite the overall, `types.__subclasses__` should be kept
& documented.
Thanks,
Joy Diamond.
1. The google search: "site:docs.python.org __subclasses__" finds no
instances of the word "__subclasses__"
2. As for what the function does, it returns the subclasses of a class:
Consider the following program:
class CryptographicActors(object): pass
class Alice(CryptographicActors): pass
class Bob(CryptographicActors): pass
print("CryptographicActors subclases: %s" %
CryptographicActors.__subclasses__())
help(CryptographicActors.__subclasses__)
3. It properly prints out:
CryptographicActors subclases: [<class '__main__.Alice'>, <class
'__main__.Bob'>]
Showing the two subclasses (`Alice` and `Bob`)
4. The internal documentation explains "__subclasses__() -> list of
immediate subclasses"
To fully figure out what it did, I had to read the source code to Python --
which really is not the best way to figure out what a function does; hence
the request to document it (and indicate it's future existence in python)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181029/85872ba5/attachment.html>
More information about the Python-ideas
mailing list