473,413 Members | 1,993 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,413 software developers and data experts.

why doesn't this filter the warning?

If I do the following code, whether in the interactive session or in a
file, I get a FutureWarning:
x = 0xffffffff <stdin>:1: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up

Okay; that's expected. No problem, I'll just turn off the
FutureWarning. Here's the results from within an interactive session:
import warnings
warnings.filterwarnings('ignore', "hex/oct constants", FutureWarning)
x = 0xffffffff


Note that no warning is produced. Great; that's what I wanted.

But now, the same thing, but executing a file, rather than
interactively:

[begin-quote]
C:\test\misc>cat testfw.py
import warnings
warnings.filterwarnings('ignore', "hex/oct constants", FutureWarning)
x = 0xffffffff

C:\test\misc>python testfw.py
testfw.py:3: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up
x = 0xffffffff
[end-quote]

Why won't the filterwarnings call suppress this?

Jul 18 '05 #1
2 3838
On Sun, Oct 17, 2004 at 06:18:06PM -0700, Terry Carroll wrote:
Why won't the filterwarnings call suppress this?


The warning is produced at the time the code is *parsed*, not when it is
*executed*. You could suppress the warning in an imported module by
putting the suppression above the import of the problem module, for
instance.

This use of 'compile' to produce a code object which is subsequently
called demonstrates the point:
c = compile("0xffffffff", "<string>", "eval") <string>:0: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up eval(c) -1

Or, without using weird functions not used from day to day, so does
this: def f(): return 0xffffffff <stdin>:1: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up f()

-1

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBcx35Jd01MZaTXX0RAn3sAKCbZqKPTRNx68gLBR8Uzw QLGwaVgwCeOUOK
H0ApHbTFeR36qXV+xXEpm4Y=
=NKXH
-----END PGP SIGNATURE-----

Jul 18 '05 #2
On Sun, 17 Oct 2004 20:35:54 -0500, Jeff Epler <je****@unpythonic.net>
wrote:
On Sun, Oct 17, 2004 at 06:18:06PM -0700, Terry Carroll wrote:
Why won't the filterwarnings call suppress this?


The warning is produced at the time the code is *parsed*, not when it is
*executed*. You could suppress the warning in an imported module by
putting the suppression above the import of the problem module, for
instance.


Thanks!

The problem code was actually:

sum = sum & 0xffffffff

Which was unnecessary, so I removed it, but I was curious why the
suppression technique, my first cut at fixing it (just in case I
misunderstood something) didn't work.
Jul 18 '05 #3

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

Similar topics

1
by: rob | last post by:
In Python 2.3, this code still prints a warning (when run as a script, not from the interpreter). How do I get rid of the warning? I'd like to do it without passing command line args to python. ...
2
by: Torsten Bronger | last post by:
Hallöchen! When I add a warning filter with warnings.filterwarnings, how can I get rid of it? I've read about resetwarnings(), but it removes all filters, even those that I didn't install in a...
3
by: arthur-e | last post by:
I can filter a query for a report on a field of a subform BUT now.... I'd like to be able to select more than one item in a multi-list box to select all the records. ALSO to use two fields (or...
7
by: MGFoster | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Access 2002 & 2003. Windows XP Professional O/S. According to the Access Help article "ApplyFilter Event" the "...ApplyFilter event occurs when...
25
by: Johan Bergman | last post by:
Hi, Maybe someone can help me to optimize this C/C++ implementation of a FIR filter (although I realize that I should probably consider an FFT approach instead.) The example below calculates...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
1
by: Luurs | last post by:
Hi All, I've been using a asp-label in the HTML <headsection for quite some time in order to dynamically generate meta-keywords,-description, css and js references. Though the actual...
3
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
6
by: AJM Project | last post by:
Hello, I see this is a well known thing and have seen many answers but none have worked for me. It's just a test page I'm making and I've ran into this so I thought I'd ask how to fix it - inline...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.