@@ -15,8 +15,9 @@ Abstract
15
15
In Python 2.7 and Python 3.2, the default warning filters were updated to hide
16
16
DeprecationWarning by default, such that deprecation warnings in development
17
17
tools that were themselves written in Python (e.g. linters, static analysers,
18
-
test runners, code generators) wouldn't be visible to their users unless they
19
-
explicitly opted in to seeing them.
18
+
test runners, code generators), as well as any other applications that merely
19
+
happened to be written in Python, wouldn't be visible to their users unless
20
+
those users explicitly opted in to seeing them.
20
21
21
22
However, this change has had the unfortunate side effect of making
22
23
DeprecationWarning markedly less effective at its primary intended purpose:
@@ -115,6 +116,55 @@ support multiple Python versions: as a more reliably visible alternative to
115
116
``DeprecationWarning`` in Python 2.7 and versions of Python 3.x prior to 3.7.
116
117
117
118
119
+
Documentation Updates
120
+
=====================
121
+
122
+
The current reference documentation for the warnings system is relatively short
123
+
on specific *examples* of possible settings for the ``-W`` command line option
124
+
or the ``PYTHONWARNINGS`` environment variably that achieve particular end
125
+
results.
126
+
127
+
The following improvements are proposed as part of the implementation of this
128
+
PEP:
129
+
130
+
* Explicitly list the following entries under the description of the
131
+
``PYTHONWARNINGS`` environment variable::
132
+
133
+
PYTHONWARNINGS=error # Convert to exceptions
134
+
PYTHONWARNINGS=always # Warn every time
135
+
PYTHONWARNINGS=default # Warn once per call location
136
+
PYTHONWARNINGS=module # Warn once per calling module
137
+
PYTHONWARNINGS=once # Warn once per Python process
138
+
PYTHONWARNINGS=ignore # Never warn
139
+
140
+
* Explicitly list the corresponding short options
141
+
(``-We``, ``-Wa``, ``-Wd``, ``-Wm``,``-Wo``, ``-Wi``) for each of the
142
+
warning actions listed under the ``-W`` command line switch documentation
143
+
144
+
* Explicitly list the default filter set in the ``warnings`` module
145
+
documentation, using the ``action::category`` and ``action::category:module``
146
+
notation
147
+
148
+
* Explicitly list the following snippet in the ``warnings.simplefilter``
149
+
documentation as a recommended approach to turning off all warnings by
150
+
default in a Python application while still allowing them to be turned
151
+
back on via ``PYTHONWARNINGS`` or the ``-W`` command line switch::
152
+
153
+
if not sys.warnoptions:
154
+
warnings.simplefilter("ignore")
155
+
156
+
None of these are *new* (they already work in all still supported Python
157
+
versions), but they're not especially obvious given the current structure
158
+
of the related documentation.
159
+
160
+
161
+
Reference Implementation
162
+
========================
163
+
164
+
A reference implementation is available in the PR [4_] linked from the
165
+
related tracker issue for this PEP [5_].
166
+
167
+
118
168
Motivation
119
169
==========
120
170
@@ -134,15 +184,20 @@ The intent was to avoid cases of tooling output like the following::
134
184
Even when `devtool` is a tool specifically for Python programmers, this is not
135
185
a particularly useful warning, as it will be shown on every invocation, even
136
186
though the main helpful step an end user can take is to report a bug to the
137
-
developers of ``devtool``. The warning is even less helpful for general purpose
138
-
developer tools that are used across more languages than just Python.
187
+
developers of ``devtool``.
188
+
189
+
The warning is even less helpful for general purpose developer tools that are
190
+
used across more languages than just Python, and almost entirely \*un\*helpful
191
+
for applications that simply happen to be written in Python, and aren't
192
+
necessarily intended for a developer audience at all.
139
193
140
194
However, this change proved to have unintended consequences for the following
141
195
audiences:
142
196
143
197
* anyone using a test runner other than the default one built into ``unittest``
144
-
(since the request for third party test runners to change their default
145
-
warnings filters was never made explicitly)
198
+
(the request for third party test runners to change their default warnings
199
+
filters was never made explicitly, so many of them still rely on the
200
+
interpreter defaults that are designed to suit deployed applications)
146
201
* anyone using the default ``unittest`` test runner to test their Python code
147
202
in a subprocess (since even ``unittest`` only adjusts the warnings settings
148
203
in the current process)
@@ -200,6 +255,15 @@ inferring API deprecations from their contents was deemed to be an intractable
200
255
code analysis problem, and an explicit function and parameter marker syntax in
201
256
annotations was proposed instead.
202
257
258
+
The CPython reference implementation will also likely see the following related
259
+
changes in 3.7:
260
+
261
+
* a new ``-X dev`` command line option that combines several developer centric
262
+
settings (including ``-Wd``) into one command line flag:
263
+
https://bugs.python.org/issue32043
264
+
* changing the behaviour in debug builds to show more of the warnings that are
265
+
off by default in regular interpeter builds
266
+
203
267
204
268
References
205
269
==========
@@ -213,6 +277,16 @@ References
213
277
.. [3] Emitting warnings based on the location of the warning itself
214
278
(https://pypi.org/project/warn/)
215
279
280
+
.. [4] GitHub PR for PEP 565 implementation
281
+
(https://github.com/python/cpython/pull/4458)
282
+
283
+
.. [5] Tracker issue for PEP 565 implementation
284
+
(https://bugs.python.org/issue31975)
285
+
286
+
.. [6] python-dev discussion thread for this PEP
287
+
(https://mail.python.org/pipermail/python-dev/2017-November/150477.html)
288
+
289
+
216
290
Copyright
217
291
=========
218
292
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4