473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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(self.dev.fileno(),0xc0047a80,struct.pa ck("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.

--
Grant Edwards grante Yow! I'm losing my
at hair...did it go to
visi.com ATLANTIC CITY??
Jul 18 '05 #1
8 2482

"Grant Edwards" <gr****@visi.com> wrote in message
news:11*************@corp.supernews.com...
How do I get rid of the following warning?
Switch to 2.4? Or is there a command line switch to do so?
<path>.py:233: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up


TJR

Jul 18 '05 #2
On 2005-03-25, Terry Reedy <tj*****@udel.edu> wrote:

"Grant Edwards" <gr****@visi.com> wrote in message
news:11*************@corp.supernews.com...
How do I get rid of the following warning?


Switch to 2.4? Or is there a command line switch to do so?


Too much work. I'd have to go upgrade a half-dozen machines. I
guess I'll just live with the warning. It sort of sucks that
you get warned about something which you can't fix.
<path>.py:233: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up


--
Grant Edwards grante Yow! I'm CONTROLLED by
at the CIA!! EVERYONE is
visi.com controlled by the CIA!!
Jul 18 '05 #3
Grant Edwards wrote:
Too much work. I'd have to go upgrade a half-dozen machines. I
guess I'll just live with the warning. It sort of sucks that
you get warned about something which you can't fix.


I'm pretty sure you can disable warnings in the warnings
module. Check the docs or archives.

-Peter
Jul 18 '05 #4
On Thu, 24 Mar 2005 23:21:39 -0000, Grant Edwards <gr****@visi.com> 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(self.dev.fileno(),0xc0047a80,struct.pa ck("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.
E.g.,
16xfc0047a80
would be explicitly negative and would not overflow 32-bit representation.
The corresponding positive value
16x0c0047a80
would overflow, of course, which would be proper.

Some discussion, including analogous spellings for other bases:

http://groups-beta.google.com/group/...3131df1e919435

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 -1073448320 hex(-2*0x40000000+0x40047a80)

__main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
and up
'0xc0047a80'

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...

Regards,
Bengt Richter
Jul 18 '05 #5
On Fri, 25 Mar 2005 03:35:29 GMT, bo**@oz.net (Bengt Richter) wrote:
On Thu, 24 Mar 2005 23:21:39 -0000, Grant Edwards <gr****@visi.com> 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(self.dev.fileno(),0xc0047a80,struct.pa ck("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.
E.g.,
16xfc0047a80
would be explicitly negative and would not overflow 32-bit representation.
The corresponding positive value
16x0c0047a80
would overflow, of course, which would be proper.

Some discussion, including analogous spellings for other bases:

http://groups-beta.google.com/group/...3131df1e919435

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 -1073448320 hex(-2*0x40000000+0x40047a80) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
and up
'0xc0047a80'

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...

I guess you could make a convenience function to convert long literals to signed i32:
def i32(x): return (x&0x80000000L and -2*0x40000000 or 0) + int(x&0x7fffffff) ... i32(0xc0047a80L)

-1073448320

so you can use i32(0xc0047a80L) where old python accepted 0xc0047a80

Regards,
Bengt Richter
Jul 18 '05 #6
Bengt Richter wrote:
>>> hex(-2*0x40000000+0x40047a80)

__main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
and up
'0xc0047a80'

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) !!


This has been discussed over and over, but since you bring it up again:

There are no hex literals for negative numbers, just as there are no
decimal literals for negative number. A literal, by nature, in any
base, is non-negative.

If you disagree: Is 0xFFF6 a positive or a negative number?

Regards,
Martin
Jul 18 '05 #7
On Sun, 27 Mar 2005 12:48:46 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <ma****@v.loewis.de> wrote:
Bengt Richter wrote:
>>> hex(-2*0x40000000+0x40047a80) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4
and up
'0xc0047a80'

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) !!


This has been discussed over and over, but since you bring it up again:

It seems you have a different concept of "this" than I ;-)
There are no hex literals for negative numbers, just as there are no
decimal literals for negative number. A literal, by nature, in any
base, is non-negative.
You are talking about what _is_, not what _can be_ ;-)

IMO a literal is a source-context-compatible string representing an abstract value
(which typically has an alternate representation in the running-program context).

AFAIK there is no law against representing negative numbers as such with whatever
literal spellings are deemed useful.
If you disagree: Is 0xFFF6 a positive or a negative number?


That is conventionally a positive number, because the python 2.4 hex syntax
is interpreted that way, as it should be now. With a leading 16x prefix instead of 0x
the rules would/could change. See below.

I am trying to propose an alternate (additional, not replacement) syntax, which
you could call base-complement. The base is specified by a prefixed <base>x where
<base> is encoded in decimal. Zero is not a legal base, so there is no problem
recognizing current hex literals.

The digits following <base>x result from the numeric value's being encoded with
the base radix, and the most significant _must_ be zero or base-1 and may be repeated
leftwards as far as desired without changing the value, which is computed by something like:

For digits on the right side (following the <base>x):
def bcdecode(s, B=10, digits='0123456789abcdefghijklmnopqrstuvwxyz'): ... if s == digits[0]: return 0
... acc = s[0].lower() == digits[B-1] and -B**len(s) or 0
... for i, c in enumerate(s[::-1]):
... acc += digits.index(c)*B**i
... return acc
...

For the whole literal (which you need, unless you are assuming you know the base
and that first digits are sign or sign leftwards-replications according to base-complement convention)
def blitdec(s): ... xpos = s.lower().index('x')
... base = int(s[:xpos])
... return bcdecode(s[xpos+1:], base)
... blitdec('2x011') 3 blitdec('2x00000011') 3 blitdec('2x101') -3 blitdec('2x11111101') -3 blitdec('16x0fff6') 65526 blitdec('16xffff6') -10 hex(blitdec('16x0fff6')) '0xfff6' hex(blitdec('16xffff6')) '-0xa'
Urk! ;-/
For backwards compatibility, hex will have to do that, but there IMO there should be
a base-complement output format available too, so e.g., (to give it a name)
baselit(blitdec('16xffff6'), 16) => '16xf6' #(normalized to single sign digit unless explicitly formatted)

BTW, blitdec('8x03') 3 blitdec('8x73') -5 blitdec('10x03') 3 blitdec('10x93') -7

The point is a bit-visualization-friendly literal representation (when desired,
and for which you'd normally use base 2, 8, or 16 ;-) of all integers.

And also it could be nice to be able to write (impossible now) compiler.parse('x=16xffff6','single')


and get
Module(None, Stmt([Assign([AssName('x', 'OP_ASSIGN')], Const(-10))]))

instead of (the result of what you have to write now)
Module(None, Stmt([Assign([AssName('x', 'OP_ASSIGN')], UnarySub(Const(10)))]))
BTW, I see the code above needs some cleaning and another .lower() or two
but I am too lazy to fix or optimize, and the corresponding
literal-formatting code is left as an exercise ;-)

Regards,
Bengt Richter
Jul 18 '05 #8
Assuming you're just trying to get rid of the message each time the program
runs, the following suppresses it:

import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
HTH,
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bengt Richter | last post by:
>>> hex(-5) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up '0xfffffffb' >>> hex(-5) '0xfffffffb' >>> hex(-5L) '-0x5L' That is sooo...
1
by: Egor Bolonev | last post by:
================= C:\Documents and Settings\ŠÕÀ³\My Documents\Scripts\octopus_eye\1\oct_eye_db.py: 213: FutureWarning: hex()/oct() of negative int will return a signed string in P ython 2.4 and...
0
by: Chris Curvey | last post by:
Hi all, When trying to automate IE thru win32com (using PAMIE), I'm getting this message out C:\Program Files\Plone 2\Python\lib\site-packages\win32com\client\dynamic.py:463 : FutureWarning:...
14
by: kosuke | last post by:
I keep getting the following error/warning message when using the python based program getmail4: /usr/lib/python2.3/optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will return a...
0
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
0
by: Steven W. Orr | last post by:
I have module M1 which has the following line in it: StartTime = safe_dict_get ( dic, 'starttime', 0xFFFFFFFF ) It gets imported by modules M2 and M3. And finally, M4 imports both M2 and M3....
5
by: Steven W. Orr | last post by:
I'm trying again, since no response indicates that I'm not providing enough info. I have module M1 which has the following line in it: StartTime = safe_dict_get ( dic, 'starttime',...
2
by: hofer | last post by:
Hi, I get following warning with a python script: optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Python 2.4 and up my code:
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.