Feature Requests item #1214675, was opened at 2005-06-04 02:37 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1214675&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: None Status: Open Resolution: None Priority: 5 Submitted By: Torsten Bronger (bronger) Assigned to: Nobody/Anonymous (nobody) Summary: module warnings lacks a remove filter function Initial Comment: In the module warnings, there is no function for removing certain items from the list of warnings filters. The only options are to empty the list completely or to manipulate the warnings.filters list directly, both of which is unfortunate in my opinion. I attached a file with a removefilter() function. I don't know how safe it is to complete regular expressions, however, it works nicely for me. ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-07-13 17:14 Message: Logged In: YES user_id=80475 Whether or not the use case is common is irrelevant if the solution is laced with problems (we don't add "works most of the time" functions). Am rejecting the removefilter() proposal. It doesn't scale-up for complex programs with multiple modules each using their own warning filters. It is too easy for innocuous looking code to violate another module's invariants. This is doubly true in a multi-threaded environment. +1 on the proposal for a Py2.5 context manager solution. That proposal is workable because the CM can specifically id() the filter that it added and later remove that exact entry if still present -- this will work even other modules have loaded an equivalent filter. To work in a threaded environement, the removal sequence should use a lock. ---------------------------------------------------------------------- Comment By: Chris Connett (cconnett) Date: 2005-07-08 13:53 Message: Logged In: YES user_id=1140166 ISTM the most common use case for this would be to set up some filter, perform some operation, then remove the filter. In this case, the removal wouldn't be far from the insertion, so it might not be unreasonable to keep around a reference to the added filter and remove it by identity when it's no longer needed ... if such a reference were available that is! As it stands, one does not get back a reference to the filter tuple added by filterwarnings(), so the only options left are to immediately grab warnings.filters[0], or construct one's own filter tuple manually (yech!). Some way should be provided to work in this case at least. As an aside, with 2.5's proposed context managers, a filter context could be added to this module so that a filter could be added and removed around the operation with a 'with' block. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2005-06-26 23:22 Message: Logged In: YES user_id=80475 I'm concerned that removefilter() may not work well in the presence of multiple modules that use the warnings module. It may be difficult to make sure the one removed wasn't subsequently added another module. Also, the issue is compounded because the order of filter application is important. ---------------------------------------------------------------------- Comment By: Michael Hudson (mwh) Date: 2005-06-04 07:48 Message: Logged In: YES user_id=6656 Pfft, this isn't Java! I'm not sure it should be done with impunity, but as a documented interface it makes perfect sense to me. ---------------------------------------------------------------------- Comment By: Torsten Bronger (bronger) Date: 2005-06-04 05:35 Message: Logged In: YES user_id=442234 It's simpler of course. However, if it's relatively easy to avoid, a module user should not manipulate module data structures directly, I think. ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-06-04 04:33 Message: Logged In: YES user_id=1188172 I don't know, but wouldn't it be simpler to just document the warnings.filters attribute so that people know how to manipulate the list of filters? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1214675&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com