This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Docs for __subclasses__(): Add hint that Python imports are lazy
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: guettli, r.david.murray
Priority: normal Keywords:

Created on 2017-07-17 14:19 by guettli, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg298527 - (view) Author: Thomas Guettler (guettli) * Date: 2017-07-17 14:19
AFAIK cls.__subclasses__() only returns the classes which the interpreter has already loaded.

This means there can be more subclasses in modules where not imported by the current interpreter up to now.

https://docs.python.org/3.7/library/stdtypes.html?highlight=subclasses#class.__subclasses__

I think it would be nice to add a hint to the docs that python imports are lazy.

What do you think?
msg298536 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-07-17 15:17
Thanks for the suggestion, but I don't think so.

Python imports are not lazy.  They are ordered.  Python is an *interpreted* language, so __subclasses__ is only going to hold those subclasses whose class definitions have been executed. This is fundamental to how the language works, and does not warrant a special note here.  Note that the entry already includes something that should give a strong hint about this even if you hadn't previously thought about it: the statement that it only includes subclasses that are "still alive".  This implies they aren't in the list until they become alive.
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75131
2017-07-17 15:17:57r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg298536

resolution: rejected
stage: resolved
2017-07-17 14:19:59guettlicreate