New submission from Terry J. Reedy <tjre...@udel.edu>:

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.
The value of an expression such as *id(666)== id(667)* is arbitrary and 
meaningless. The id of the first int object might or might not be reused for 
the second one.

----------
assignee: docs@python
components: Documentation
messages: 145743
nosy: docs@python, terry.reedy
priority: normal
severity: normal
status: open
title: Doc: say id() is only useful for existing objects
versions: Python 2.7, Python 3.2, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13203>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to