[Python-Dev] test warnings for "%x"%id(foo) on 2.3 branch
Guido van Rossum
guido at python.org
Wed Nov 5 09:58:32 EST 2003
> > I'd reformulate them as
> >
> > "%x" % (id(o) & 0xffffffffL)
> > Of course, you have to replace 0xffffffffL with (unsigned)-1 of the
> > system (i.e. 2l*sys.maxint+1).
>
> Hm. "%x" % (id(o) & 2L*sys.maxint+1)
>
> is considerably less obvious that "%x"%id(o)
>
> > I wonder whether creating a function
> > sys.unsigned(id(o))
> > would be appropriate, which returns its arguments for positive
> > numbers, and PyLong_FromUnsignedLong((unsigned)arg) otherwise.
>
> Possibly. I'm going to have to make the above patch to the 23 branch
> in any case - warnings from the standard test suite are bad. Would a
> different % format code be another option?
This warning will go away in 2.4 again, where %x with a negative int
will return a hex number with a minus sign. So I'd be against
introducing a new format code. I've forgotten in what code you found
this, but the sys.maxint solution sounds like your best bet. In 2.4
we can also make id() return a long when the int value would be
negative; I don't want to do that in 2.3 since changing the return
type and value of a builtin in a minor release seems a compatibility
liability -- but in 2.4 the difference between int and long will be
wiped out even more than it already is, so it should be fine there.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list