Title: Docs for __subclasses__(): Add hint that Python imports are lazy
Type: Stage: resolved
Components: Versions:
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 2017-07-17 15:17 by r.david.murray. 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.

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.
Date User Action Args
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