From 09f3a8a1249308a104a89041d82fe99e6c087043 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Nov 2017 17:32:40 -0800 Subject: 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. --- Lib/warnings.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Lib/warnings.py') diff --git a/Lib/warnings.py b/Lib/warnings.py index 48d5e163d1..b2605f84ae 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 -- cgit v1.2.1