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

Anthony Baxter anthony at interlink.com.au
Wed Nov 5 22:15:46 EST 2003


>>> Guido van Rossum wrote
> 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.

The code is basically something like this:

Python 2.3.2+ (#1, Nov  5 2003, 00:54:02) 
[GCC 3.3.1 20030930 (Red Hat Linux 3.3.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class a: pass
... 
>>> b=a()
>>> repr(b) == '<__main__.a instance at 0x%x>'%id(b)
__main__:1: FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Python 2.4 and up
True
>>> 

For now, I'll patch the 2.3 code in the test suite to make it not complain.

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.

Anthony



More information about the Python-Dev mailing list