[Python-Dev] Redirecting warnings.showwarning to logging

Scott David Daniels Scott.Daniels at Acm.Org
Sat Nov 22 23:44:32 CET 2008

Scott David Daniels wrote:
 > Match the new warning protocol exactly:
 >     def showwarning(message, category, filename, lineno,
 >                     file=None, line=None):
 >         ...
 >     If the line is not None, use it (which will happen if you pass it
 >     along to showwarning).
 >     If the line is None and file is not None, use file to get to your
 >     line, rather than opening the filename which may not work.

Sorry, this had no sooner left my terminal than I realized that the file
argument is the output target, and nothing to do with fetching source.
I'd not put the data into the log if file is provided, because it may
be code trying to extract output formatting.

I'd do something like this:
     if file is not None:
         old_showwarning(message, category, filename, lineno, file, line)
at the top of the code.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-Dev mailing list