summaryrefslogtreecommitdiffstats
path: root/Lib/warnings.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-12-12 21:59:48 (GMT)
committerGitHub <noreply@github.com>2017-12-12 21:59:48 (GMT)
commit747f48e2e92390c44c72f52a1239959601cde157 (patch)
tree502e53b129aee7a393ca6d05e4f93751919a5e1b /Lib/warnings.py
parentb748e3b2586e44bfc7011b601bce9cc6d16d89f1 (diff)
downloadcpython-747f48e2e92390c44c72f52a1239959601cde157.zip
cpython-747f48e2e92390c44c72f52a1239959601cde157.tar.gz
cpython-747f48e2e92390c44c72f52a1239959601cde157.tar.bz2
bpo-32230: Set sys.warnoptions with -X dev (#4820)
Rather than supporting dev mode directly in the warnings module, this instead adjusts the initialisation code to add an extra 'default' entry to sys.warnoptions when dev mode is enabled. This ensures that dev mode behaves *exactly* as if `-Wdefault` had been passed on the command line, including in the way it interacts with `sys.warnoptions`, and with other command line flags like `-bb`. Fix also bpo-20361: have -b & -bb options take precedence over any other warnings options. Patch written by Nick Coghlan, with minor modifications of Victor Stinner.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r--Lib/warnings.py35
1 files changed, 6 insertions, 29 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py
index 4e7241f..f4331c8 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -519,34 +519,11 @@ except ImportError:
# Module initialization
_processoptions(sys.warnoptions)
if not _warnings_defaults:
- dev_mode = ('dev' in getattr(sys, '_xoptions', {}))
- py_debug = hasattr(sys, 'gettotalrefcount')
-
- if not(dev_mode or py_debug):
- silence = [ImportWarning, PendingDeprecationWarning]
- silence.append(DeprecationWarning)
- for cls in silence:
- simplefilter("ignore", category=cls)
-
- bytes_warning = sys.flags.bytes_warning
- if bytes_warning > 1:
- bytes_action = "error"
- elif bytes_warning:
- bytes_action = "default"
- else:
- bytes_action = "ignore"
- simplefilter(bytes_action, category=BytesWarning, append=1)
-
- # resource usage warnings are enabled by default in pydebug mode
- if dev_mode or py_debug:
- resource_action = "default"
- 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
+ # Several warning categories are ignored by default in Py_DEBUG builds
+ if not hasattr(sys, 'gettotalrefcount'):
+ simplefilter("ignore", category=DeprecationWarning, append=1)
+ simplefilter("ignore", category=PendingDeprecationWarning, append=1)
+ simplefilter("ignore", category=ImportWarning, append=1)
+ simplefilter("ignore", category=ResourceWarning, append=1)
del _warnings_defaults