summaryrefslogtreecommitdiffstats
path: root/Lib/warnings.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-09-18 00:42:05 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-09-18 00:42:05 (GMT)
commit87538e7bc46885d2ad2cce423603b45d182d6d40 (patch)
tree732e291a58b2eeedab44f04d9b9f504a5960ae68 /Lib/warnings.py
parent605a64b4360c552b20fc74d1ab51dd5bdd98e1ae (diff)
parentcb0a006fd11c06178a656cfdc6390b197b22fc67 (diff)
downloadcpython-87538e7bc46885d2ad2cce423603b45d182d6d40.zip
cpython-87538e7bc46885d2ad2cce423603b45d182d6d40.tar.gz
cpython-87538e7bc46885d2ad2cce423603b45d182d6d40.tar.bz2
Issue #4180: The warnings registries are now reset when the filters are modified.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r--Lib/warnings.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py
index e53efa5..f731925 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -53,6 +53,7 @@ def filterwarnings(action, message="", category=Warning, module="", lineno=0,
filters.append(item)
else:
filters.insert(0, item)
+ _filters_mutated()
def simplefilter(action, category=Warning, lineno=0, append=False):
"""Insert a simple entry into the list of warnings filters (at the front).
@@ -73,10 +74,12 @@ def simplefilter(action, category=Warning, lineno=0, append=False):
filters.append(item)
else:
filters.insert(0, item)
+ _filters_mutated()
def resetwarnings():
"""Clear the list of warning filters, so that no filters are active."""
filters[:] = []
+ _filters_mutated()
class _OptionError(Exception):
"""Exception used by option processing helpers."""
@@ -206,6 +209,9 @@ def warn_explicit(message, category, filename, lineno,
module = module[:-3] # XXX What about leading pathname?
if registry is None:
registry = {}
+ if registry.get('version', 0) != _filters_version:
+ registry.clear()
+ registry['version'] = _filters_version
if isinstance(message, Warning):
text = str(message)
category = message.__class__
@@ -331,6 +337,7 @@ class catch_warnings(object):
self._entered = True
self._filters = self._module.filters
self._module.filters = self._filters[:]
+ self._module._filters_mutated()
self._showwarning = self._module.showwarning
if self._record:
log = []
@@ -345,6 +352,7 @@ class catch_warnings(object):
if not self._entered:
raise RuntimeError("Cannot exit %r without entering first" % self)
self._module.filters = self._filters
+ self._module._filters_mutated()
self._module.showwarning = self._showwarning
@@ -359,15 +367,22 @@ class catch_warnings(object):
_warnings_defaults = False
try:
from _warnings import (filters, _defaultaction, _onceregistry,
- warn, warn_explicit)
+ warn, warn_explicit, _filters_mutated)
defaultaction = _defaultaction
onceregistry = _onceregistry
_warnings_defaults = True
+
except ImportError:
filters = []
defaultaction = "default"
onceregistry = {}
+ _filters_version = 1
+
+ def _filters_mutated():
+ global _filters_version
+ _filters_version += 1
+
# Module initialization
_processoptions(sys.warnoptions)