[issue18383] test_warnings modifies warnings.filters when running with "-W default"
Alex Shkop
report at bugs.python.org
Mon Mar 2 16:24:04 CET 2015
Alex Shkop added the comment:
The issue occurs only if C implementation of _warnings is available. It is caused by re-use of global filters variable from _warnings when warnings is being re-imported.
So warnings modifies _warnings.filters on first import. Then, when you import warnings again it uses already modified version of _warnings.filters and adds same filter for the second time.
I attach a simple patch that prevents duplicates in filters. I'm not sure if this is a best way to fix the problem, but it works. It certainly affects performance of filterwarnings(), but there shouldn't be a lot of filters anyway.
Making filters a set() will solve the problem also, but will require API changes. Although I didn't find anywhere in documentation that warnings.filters should be a list, someone might rely on its .append() method.
----------
nosy: +ashkop
Added file: http://bugs.python.org/file38301/issue18383_remove_dups.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18383>
_______________________________________
More information about the Python-bugs-list
mailing list