Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for __subclasses__(): Add hint that Python imports are lazy #75131

Closed
guettli mannequin opened this issue Jul 17, 2017 · 2 comments
Closed

Docs for __subclasses__(): Add hint that Python imports are lazy #75131

guettli mannequin opened this issue Jul 17, 2017 · 2 comments

Comments

@guettli
Copy link
Mannequin

guettli mannequin commented Jul 17, 2017

BPO 30948
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2017-07-17.15:17:57.978>
created_at = <Date 2017-07-17.14:19:59.603>
labels = []
title = 'Docs for __subclasses__(): Add hint that Python imports are lazy'
updated_at = <Date 2017-07-17.15:17:57.976>
user = 'https://bugs.python.org/guettli'

bugs.python.org fields:

activity = <Date 2017-07-17.15:17:57.976>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2017-07-17.15:17:57.978>
closer = 'r.david.murray'
components = []
creation = <Date 2017-07-17.14:19:59.603>
creator = 'guettli'
dependencies = []
files = []
hgrepos = []
issue_num = 30948
keywords = []
message_count = 2.0
messages = ['298527', '298536']
nosy_count = 2.0
nosy_names = ['guettli', 'r.david.murray']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue30948'
versions = []

@guettli
Copy link
Mannequin Author

guettli mannequin commented Jul 17, 2017

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?

@bitdancer
Copy link
Member

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant