[Python-Dev] test warnings for "%x"%id(foo) on 2.3 branch

Guido van Rossum guido at python.org
Thu Nov 6 00:41:17 EST 2003


> If %x will return a negative hex number, then the internals of id()
> must make sure that they return a positive number, or whatever does
> the standard repr will need to change as well. I'll log a bug on SF
> for it.

The standard repr is written in C and uses %p, which does a platform
specific thing, but typically produces an unsigned hex number of
appropriate length; apparently we've not been ported to platforms
where it does something else, otherwise the test would have failed
there too.  One can argue that the test is too constrained anyway --
why should we care about the specific hex number in the repr() of a
class?

I'm not for adding %p to Python's string formats; it's too
implementation specific and I don't see a use for it other than
matching the built-in repr().

id() has always returned negative numbers on all platforms where
pointers happen to have the high bit set; apart from making this test
pass in the future (which is a pretty weak argument) I don't see a
problem with that, so I'm not in favor of changing it, even though it
would be easy enough to change PyLong_FromVoidPtr() to call
PyLong_FromLong[Long]().

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list