By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Retry: Question about FutureWarning

P: n/a
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', 0xFFFFFFFF )

It gets imported by modules M2 and M3. And finally, M4 imports both M2 and
M3. So the idea is that in total we have 4 files called M1.py M2.py M3.py
and M4.py

M4
|\M3
| |\M1
|\M2
| |\M1

I need to compile the python modules as part of the package building
process.

The shell compile command I use to generate both the .pyc and the .pyo
files is:

python=/usr/bin/python2.3
i_python ()
{
$python -c "import $1"
$python -O -c "import $1"
}
i_python M1
i_python M2
i_python M3
i_python M4

When M1 is compiled, there's no problem. The same for when I compile M2
and M3. But when M4 is compiled, I get the following message:

M1.py:268: FutureWarning: hex/oct constants sys.maxint will
return positive values in Python 2.4 and up
StartTime = safe_dict_get ( dic, 'starttime', 0xFFFFFFFF )

I get the message twice, ostensibly because of M3 and M2 both being
imported into M1

I was able to shut off the warning by adding the following lines *before*
the import of M2 and M3 in M4:

import warnings
warnings.filterwarnings('ignore', category=FutureWarning)

My question is this: Why can the warning not be shut off by putting the
two lines in M1 where the reference exists to 0xFFFFFFFF ?

I'm just leary of fixing warnings by looking for ways to shut them off.

Also, do I need to supply any more information?

Thanks for your patience.

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
Aug 15 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Steven W. Orr wrote:
M1.py:268: FutureWarning: hex/oct constants sys.maxint will
return positive values in Python 2.4 and up
StartTime = safe_dict_get ( dic, 'starttime', 0xFFFFFFFF )
...
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)

My question is this: Why can the warning not be shut off by putting the
two lines in M1 where the reference exists to 0xFFFFFFFF ?
You really don't want to shut off the warning; it means just what it says:

Python 2.3.5 (#1, Feb 8 2005, 23:36:23)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>0xffffffff
<stdin>:1: FutureWarning: hex/oct constants sys.maxint will return
positive values in Python 2.4 and up
-1

Python 2.4.3 (#1, Mar 29 2006, 17:16:11)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>0xffffffff
4294967295L

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
Black vinyl man with black plasticized imagination
-- Nik Kershaw
Aug 15 '07 #2

P: n/a
On Aug 14, 8:49 pm, Erik Max Francis <m...@alcyone.comwrote:
Steven W. Orr wrote:
M1.py:268: FutureWarning: hex/oct constants sys.maxint will
return positive values in Python 2.4 and up
StartTime = safe_dict_get ( dic, 'starttime', 0xFFFFFFFF )
...
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
My question is this: Why can the warning not be shut off by putting the
two lines in M1 where the reference exists to 0xFFFFFFFF ?

You really don't want to shut off the warning; it means just what it says:

Python 2.3.5 (#1, Feb 8 2005, 23:36:23)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>0xffffffff
<stdin>:1: FutureWarning: hex/oct constants sys.maxint will return
positive values in Python 2.4 and up
-1

Python 2.4.3 (#1, Mar 29 2006, 17:16:11)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>0xffffffff
4294967295L

--
Erik Max Francis && m...@alcyone.com &&http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
Black vinyl man with black plasticized imagination
-- Nik Kershaw
So if by '0xFFFFFFFF' you meant -1, then change this line to use -1.
Otherwise, if you really meant 4294967295L, leave it at 0xFFFFFFFF and
move on.

-- Paul

Aug 15 '07 #3

P: n/a
On 2007-08-15, Paul McGuire <pt***@austin.rr.comwrote:
On Aug 14, 8:49 pm, Erik Max Francis <m...@alcyone.comwrote:

So if by '0xFFFFFFFF' you meant -1, then change this line to use -1.
Otherwise, if you really meant 4294967295L, leave it at 0xFFFFFFFF and
move on.
A third option is to specify 0xFFFFFFFF as 0xFFFFFFFFL in the latter case to
get rid of the warning.

Albert
Aug 15 '07 #4

P: n/a
Thanks guys, but that's not my question. The question is this: Why does
the call to filterwarnings not work if it's placed inside the M1 module?
Why do I have to place the call in M4 to make it work? This is more a
question about how import works than it is about what the value of -1 is.
;-)

On Tuesday, Aug 14th 2007 at 18:49 -0700, quoth Erik Max Francis:

=>Steven W. Orr wrote:
=>
=>M1.py:268: FutureWarning: hex/oct constants sys.maxint will
=>return positive values in Python 2.4 and up
=> StartTime = safe_dict_get ( dic, 'starttime', 0xFFFFFFFF )
=> ...
=>import warnings
=>warnings.filterwarnings('ignore', category=FutureWarning)
=>>
=>My question is this: Why can the warning not be shut off by putting the
=>two lines in M1 where the reference exists to 0xFFFFFFFF ?
=>
=>You really don't want to shut off the warning; it means just what it says:
=>
=>Python 2.3.5 (#1, Feb 8 2005, 23:36:23)
=>[GCC 3.2.3] on linux2
=>Type "help", "copyright", "credits" or "license" for more information.
=>0xffffffff
=><stdin>:1: FutureWarning: hex/oct constants sys.maxint will return
=>positive values in Python 2.4 and up
=>-1
=>
=>Python 2.4.3 (#1, Mar 29 2006, 17:16:11)
=>[GCC 3.2.3] on linux2
=>Type "help", "copyright", "credits" or "license" for more information.
=>0xffffffff
=>4294967295L
=>

On Wednesday, Aug 15th 2007 at 06:10 -0700, quoth Paul McGuire:

=>On Aug 14, 8:49 pm, Erik Max Francis <m...@alcyone.comwrote:
=>
=>So if by '0xFFFFFFFF' you meant -1, then change this line to use -1.
=>Otherwise, if you really meant 4294967295L, leave it at 0xFFFFFFFF and
=>move on.
=>
=>-- Paul
=>
=>--
=>http://mail.python.org/mailman/listinfo/python-list
=>

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
Aug 15 '07 #5

P: n/a
Steven W. Orr wrote:
I'm trying again, since no response indicates that I'm not providing
enough info.
No, you were providing too much irrelevant information. It would have been
better to put it that way:
Thanks guys, but that's not my question. The question is this: Why does
the call to filterwarnings not work if it's placed inside the M1 module?
Why do I have to place the call in M4 to make it work? This is more a
question about how import works than it is about what the value of -1 is.
;-)
You cannot switch off the warning inside the module because it is issued
during its compilation, not its execution:

$ cat tmp.py
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
print "FutureWarning switched off"
warnings.warn("yadda", category=FutureWarning)
0xffffffff

$ rm tmp.pyc
$ python2.3 -c'import tmp'
tmp.py:5: FutureWarning: hex/oct constants sys.maxint will return positive
values in Python 2.4 and up
0xffffffff
FutureWarning switched off

First you get the warning, then the "switched off" message. Oops.

$ python2.3 -c'import tmp'
FutureWarning switched off

When importing the module a second time you don't get the warning because
the compiled module already exists and is reused.

Note that you can disable warnings on the commmand line...

$ rm tmp.pyc
$ python2.3 -Wignore::FutureWarning -c'import tmp'
FutureWarning switched off

.... but as others already told you it is normally not a good idea to squash
these warnings. Well, you have been warned ;)

Peter
Aug 16 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.