-W: Python bug? Documentation bug?

C

Clarence

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./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.
$ 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.
 
C

Clarence

Clarence said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top