How to get rid of FutureWarning: hex/oct constants...

Bengt Richter bokr at
Fri Mar 25 04:35:29 CET 2005

On Thu, 24 Mar 2005 23:21:39 -0000, Grant Edwards <grante at> wrote:

>How do I get rid of the following warning?
>  <path>.py:233: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up
>  fcntl.ioctl(,0xc0047a80,struct.pack("HBB",i,0,0))
>I tried using 0xc0047a80L.  That got rid of the warning, but
>then I got an exception when fcntl.ioctl() was called because
>the long int was too large to be converted to an int.
Lobby for a PEP for numeric literals allowing representation
of negative numbers without writing a unary minus expression.
would be explicitly negative and would not overflow 32-bit representation.
The corresponding positive value
would overflow, of course, which would be proper.

Some discussion, including analogous spellings for other bases:

In the meantime, maybe (ugh):

 Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> -2*0x40000000+0x40047a80
 >>> hex(-2*0x40000000+0x40047a80)
 __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
  and up

That "signed string" is a unary minus expression using an absolute value forced by the inadequacy
of the literal representation syntax.
IOW, IMO '-' + hex_literal_of(abs(x)) is not a decent hex_literal_of(-x) !!
Urk and argh...

Bengt Richter

More information about the Python-list mailing list