diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-11-21 01:32:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-21 01:32:40 (GMT) |
commit | 09f3a8a1249308a104a89041d82fe99e6c087043 (patch) | |
tree | 2d494c186b4aadfb6fe630f8ac9fc7e66e1906f5 /Lib/warnings.py | |
parent | f39b674876d2bd47ec7fc106d673b60ff24092ca (diff) | |
download | cpython-09f3a8a1249308a104a89041d82fe99e6c087043.zip cpython-09f3a8a1249308a104a89041d82fe99e6c087043.tar.gz cpython-09f3a8a1249308a104a89041d82fe99e6c087043.tar.bz2 |
bpo-32089: Fix warnings filters in dev mode (#4482)
The developer mode (-X dev) now creates all default warnings filters
to order filters in the correct order to always show ResourceWarning
and make BytesWarning depend on the -b option.
Write a functional test to make sure that ResourceWarning is logged
twice at the same location in the developer mode.
Add a new 'dev_mode' field to _PyCoreConfig.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r-- | Lib/warnings.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py index 48d5e16..b2605f8 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -486,7 +486,6 @@ class catch_warnings(object): # - a compiled regex that must match the module that is being warned # - a line number for the line being warning, or 0 to mean any line # If either if the compiled regexs are None, match anything. -_warnings_defaults = False try: from _warnings import (filters, _defaultaction, _onceregistry, warn, warn_explicit, _filters_mutated) @@ -504,12 +503,16 @@ except ImportError: global _filters_version _filters_version += 1 + _warnings_defaults = False + # Module initialization _processoptions(sys.warnoptions) if not _warnings_defaults: + dev_mode = ('dev' in getattr(sys, '_xoptions', {})) py_debug = hasattr(sys, 'gettotalrefcount') - if not py_debug: + + if not(dev_mode or py_debug): silence = [ImportWarning, PendingDeprecationWarning] silence.append(DeprecationWarning) for cls in silence: @@ -525,10 +528,15 @@ if not _warnings_defaults: simplefilter(bytes_action, category=BytesWarning, append=1) # resource usage warnings are enabled by default in pydebug mode - if py_debug: + if dev_mode or py_debug: resource_action = "always" else: resource_action = "ignore" simplefilter(resource_action, category=ResourceWarning, append=1) + if dev_mode: + simplefilter("default", category=Warning, append=1) + + del py_debug, dev_mode + del _warnings_defaults |