Message237050
| Author |
ashkop |
| Recipients |
ashkop, ezio.melotti, flox, serhiy.storchaka |
| Date |
2015年03月02日.15:24:04 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1425309844.51.0.837899954192.issue18383@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015年03月02日 15:24:04 | ashkop | set | recipients:
+ ashkop, ezio.melotti, flox, serhiy.storchaka |
| 2015年03月02日 15:24:04 | ashkop | set | messageid: <1425309844.51.0.837899954192.issue18383@psf.upfronthosting.co.za> |
| 2015年03月02日 15:24:04 | ashkop | link | issue18383 messages |
| 2015年03月02日 15:24:04 | ashkop | create |
|