why doesn't this filter the warning?

Jeff Epler jepler at unpythonic.net
Sun Oct 17 21:35:54 EDT 2004


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041017/ad4d9ad9/attachment.sig>


More information about the Python-list mailing list