467,858 Members | 1,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

-W: Python bug? Documentation bug?

It appears that the -W option on starting python doesn't work the same
as the warnings module. In particular, the "message" parameter is not
treated as a regular expression, but rather a string literal which must
appear at the beginning of a warning message in order to match. The
treatment of -W in "python -h" makes no mention of the warnings module
(and I actually couldn't find any definitive documentation on command
line switches), though the documentation for the warnings module does
say:

The interpreter saves the arguments for all -W options without
interpretation
in sys.warnoptions; the warnings module parses these when it is
first imported

That also kind of maybe implies that warnings is automatically imported
by the interpreter, but it doesn't actually say so.

How should this be treated?

=========
Here's an example of the problem. (I've reproduced it in version 2.5
also)

$ python -W ignore:whenThreaded
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
/usr/local/lib/python2.4/site-packages/twisted/internet/base.py:245:
DeprecationWarning: threadable.whenThreaded is deprecated. Use
application-level logic instead.
threadable.whenThreaded(self.initThreads)
>>>
$ python -W ignore:'threadable.whenThreaded is deprecated. Use
application-level logic instead.'
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
$ python -W ignore:threadable.whenThreaded
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
Dec 13 '06 #1
  • viewed: 1304
Share:
1 Reply

Clarence wrote:
It appears that the -W option on starting python doesn't work the same
as the warnings module. In particular, the "message" parameter is not
treated as a regular expression, but rather a string literal which must
appear at the beginning of a warning message in order to match. The
I must have gotten confused during my testing. The behavior is the same
whether coming from the command line or from within the program.
However, I see that the regular expression is being tested using
re.match rather than re.search. Does that seem correct to people? At
the least, that should be mentioned in the documentation.

Dec 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.