[New-bugs-announce] [issue13203] Doc: say id() is only useful for existing objects

Terry J. Reedy report at bugs.python.org
Mon Oct 17 19:50:35 CEST 2011

New submission from Terry J. Reedy <tjreedy at udel.edu>:

Newbies too often do something like (3.2.2, )

>>> id(getattr(x, 'pop')) == id(x.pop)

and get confused by the (invalid) result, whereas

>>> a,b=getattr(x, 'pop'),x.pop
>>> id(a)==id(b)

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 at python
components: Documentation
messages: 145743
nosy: docs at 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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list