[Python-ideas] Decide if `type.__subclasses__` is part of future Python or not
Guido van Rossum
guido at python.org
Mon Oct 29 14:15:32 EDT 2018
__subclasses__ is a runtime thing. As such it should probably be documented
-- someone should submit a doc PR. I don't think that "overhaul" is the
right word to describe what's going to happen with types in Python -- yes,
we're adding optional static type checking, and yes, this will occasionally
result in changed recommendations for how the language should be used or
how APIs should be designed, but no, this does not mean that we're planning
to deprecate or remove existing runtime features.
On Mon, Oct 29, 2018 at 11:12 AM Joy Diamond <python.gem at gmail.com> wrote:
> 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
> 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.
> 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" %
> 3. It properly prints out:
> CryptographicActors subclases: [<class '__main__.Alice'>, <class
> 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-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas