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
Doc: say id() is only useful for existing objects #57412
Comments
Newbies too often do something like (3.2.2, ) >>> id(getattr(x, 'pop')) == id(x.pop)
True and get confused by the (invalid) result, whereas >>> a,b=getattr(x, 'pop'),x.pop
>>> id(a)==id(b)
False works properly. I think we should add a sentence or two or three to the id() doc, such as Since a newly created argument object is either destroyed or becomes inaccessible before the function returns, *id(obj)* is only useful and valid if *obj* exists prior to the call and therefore after its return. |
If we add something at all, it should be much shorter. After all, the current doc already states "unique during its lifetime". |
I gave a maximum addition. The first sentence may be enough (or even just the second half of it). What people do not get is that the lifetime of new arg objects is the duration of the function call -- and that the output of id for departed objects is uniquely useless and invalid. |
I think this is over-explaining an implementation detail and it makes the docs for id() harder to understand. Possibly there can be a FAQ entry about identity but the id() function itself is no place to go into the quirks of when new objects are created or destroyed. Also, "getting confused" is often a step in the learning process -- it can't be taken out entirely. |
A FAQ entry sounds good to me. |
Suggestion attached. |
LGTM
If you want to be more accurate you could say "before and after" instead of "during". |
New changeset 8525cc1f342f by Georg Brandl in branch '2.7': |
New changeset 0d5de993db66 by Georg Brandl in branch '3.3': |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: