[Python-Dev] builtin_id() returns negative numbers

Nick Coghlan ncoghlan at iinet.net.au
Tue Feb 15 10:43:30 CET 2005

Josiah Carlson wrote:
>>>Python doesn't promise to return a postive integer for id(), although
>>>it may have been nicer if it did.  It's dangerous to change that now,
>>>because some code does depend on the "32 bit-ness as a signed integer"
>>>accident of CPython's id() implementation on 32-bit machines.  For
>>>example, code using struct.pack(), or code using one of ZODB's
>>>specialized int-key BTree types with id's as keys.
> All Tim was saying is that you can't /change/ builtin_id() because of
> backwards compatibiliity with Zope and struct.pack().  You are free to
> create a positive_id() function, and request its inclusion into builtins
> (low probability; people don't like doing that). Heck, you are even free
> to drop it in your local site.py implementation.  But changing the
> current function is probably a no-no.

There's always the traditional response to "want to fix it but can't due to 
backwards compatibility": a keyword argument that defaults to False.


Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia

More information about the Python-Dev mailing list