[Python-Dev] Redirecting warnings.showwarning to logging

Brett Cannon brett at python.org
Sun Nov 23 03:58:59 CET 2008


On Sat, Nov 22, 2008 at 17:53, Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
> 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.
>

It is specifically there to be overridden (and as an aside, it was a
pain to support in the C port of warnings), so it really isn't
monkey-patching. =)

-Brett


More information about the Python-Dev mailing list