[Python-Dev] Redirecting warnings.showwarning to logging

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Nov 23 02:53:35 CET 2008

Sidnei da Silva <sidnei <at> enfoldsystems.com> writes:

> I do have one suggestion for improvement: instead of requiring the
> person to do this monkey patching, add a new 'log' action to the
> warnings filter as described by PEP 230 [1] (see: 'The Warnings
> Filter' section). This way, changing the behavior of how warnings are
> displayed (or not) is kept consistent and documented.
> [1] http://www.python.org/dev/peps/pep-0230/

I see from PEP-230 the following under "Rejected Concerns" stated by GvR:

"Paul Prescod, Barry Warsaw and Fred Drake have brought up several additional
concerns that I feel aren't critical.  I address them here (the concerns are
paraphrased, not exactly their words):"

    [other concerns omitted]
    - Barry: I'd like to add my own warning action.  Maybe if `action'
      could be a callable as well as a string.  Then in my IDE, I
      could set that to "mygui.popupWarningsDialog".

      Response: For that purpose you would override warnings.showwarning().
    [other concerns omitted]

So, monkey-patching appears to be the suggested approach. Indeed, ISTM that the
showwarning function is there specifically for the purpose of being
monkey-patched out.


Vinay Sajip

More information about the Python-Dev mailing list