[ python-Bugs-1191104 ] Warning ``error`` filter action is ignored.

SourceForge.net noreply at sourceforge.net
Fri Apr 29 04:54:48 CEST 2005


Bugs item #1191104, was opened at 2005-04-27 10:55
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1191104&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Ivan Vilata i Balaguer (ivilata)
>Assigned to: Vinay Sajip (vsajip)
Summary: Warning ``error`` filter action is ignored.

Initial Comment:
Hi all.  It seems that setting the ``error`` action on
a warning message once it has already been triggered
does not allow it to be triggered again.  As usual, the
code is clearer than the explanation::

    import warnings

    def do_warn():
        warnings.warn("A warning.", DeprecationWarning)

    do_warn()

    warnings.filterwarnings('error',
category=DeprecationWarning)
    do_warn()

    warnings.filterwarnings('always',
category=DeprecationWarning)
   do_warn()

The output of this program is::

    nowarn.py:4: DeprecationWarning: A warning.
      warnings.warn("A warning.", DeprecationWarning)

There is no exception raised, though the filter was
instructed to turn the warning into an error.  Take
note that using ``always`` has similar results.

Does it work in that way on purpose?  I find it quite
counterintuitive, IMHO.  If this behaviour is intended,
what would be the way to turn the second warning into
an exception?

Thanks!

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1191104&group_id=5470


More information about the Python-bugs-list mailing list