A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20100110/db6da5fd/attachment-0007.htm below:

Nick Coghlan thought I should forward this to python-dev so people are aware of this change and why it occurred (plus it indirectly informs Guido I finally finished the work).<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>

From: <b class="gmail_sendername">brett.cannon</b> <span dir="ltr">&lt;<a href="mailto:python-checkins@python.org">python-checkins@python.org</a>&gt;</span><br>Date: Sat, Jan 9, 2010 at 18:56<br>Subject: [Python-checkins] r77402 - in python/trunk: Doc/library/warnings.rst Lib/test/test_ascii_formatd.py Lib/test/test_exceptions.py Lib/warnings.py Misc/NEWS Python/_warnings.c<br>

To: <a href="mailto:python-checkins@python.org">python-checkins@python.org</a><br><br><br>Author: brett.cannon<br>


Date: Sun Jan 10 03:56:19 2010<br>
New Revision: 77402<br>
<br>
Log:<br>
DeprecationWarning is now silent by default.<br>
<br>
This was originally suggested by Guido, discussed on the stdlib-sig mailing<br>
list, and given the OK by Guido directly to me. What this change essentially<br>
means is that Python has taken a policy of silencing warnings that are only<br>
of interest to developers by default. This should prevent users from seeing<br>
warnings which are triggered by an application being run against a new<br>
interpreter before the app developer has a chance to update their code.<br>
<br>
Closes issue #7319. Thanks to Antoine Pitrou, Ezio Melotti, and Brian Curtin<br>
for helping with the issue.<br>
<br>
<br>
Modified:<br>
 Â  python/trunk/Doc/library/warnings.rst<br>
 Â  python/trunk/Lib/test/test_ascii_formatd.py<br>
 Â  python/trunk/Lib/test/test_exceptions.py<br>
 Â  python/trunk/Lib/warnings.py<br>
 Â  python/trunk/Misc/NEWS<br>
 Â  python/trunk/Python/_warnings.c<br>
<br>
Modified: python/trunk/Doc/library/warnings.rst<br>
==============================================================================<br>
--- python/trunk/Doc/library/warnings.rst Â  Â  Â  (original)<br>
+++ python/trunk/Doc/library/warnings.rst Â  Â  Â  Sun Jan 10 03:56:19 2010<br>
@@ -59,7 +59,7 @@<br>
 | :exc:`UserWarning` Â  Â  Â  Â  Â  Â  Â  | The default category for :func:`warn`. Â  Â  Â  Â |<br>
 +----------------------------------+-----------------------------------------------+<br>
 | :exc:`DeprecationWarning` Â  Â  Â  Â | Base category for warnings about deprecated Â  |<br>
-| Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â | features. Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  |<br>
+| Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â | features (ignored by default). Â  Â  Â  Â  Â  Â  Â  Â |<br>
 +----------------------------------+-----------------------------------------------+<br>
 | :exc:`SyntaxWarning` Â  Â  Â  Â  Â  Â  | Base category for warnings about dubious Â  Â  Â |<br>
 | Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â | syntactic features. Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  |<br>
@@ -89,6 +89,9 @@<br>
 standard warning categories. Â A warning category must always be a subclass of<br>
 the :exc:`Warning` class.<br>
<br>
+.. versionchanged:: 2.7<br>
+ Â  :exc:`DeprecationWarning` is ignored by default.<br>
+<br>
<br>
 .. _warning-filter:<br>
<br>
@@ -148,14 +151,6 @@<br>
 :mod:`warnings` module parses these when it is first imported (invalid options<br>
 are ignored, after printing a message to ``sys.stderr``).<br>
<br>
-The warnings that are ignored by default may be enabled by passing :option:`-Wd`<br>
-to the interpreter. This enables default handling for all warnings, including<br>
-those that are normally ignored by default. This is particular useful for<br>
-enabling ImportWarning when debugging problems importing a developed package.<br>
-ImportWarning can also be enabled explicitly in Python code using::<br>
-<br>
- Â  warnings.simplefilter(&#39;default&#39;, ImportWarning)<br>
-<br>
<br>
 .. _warning-suppress:<br>
<br>
@@ -226,6 +221,37 @@<br>
 entries from the warnings list before each new operation).<br>
<br>
<br>
+Updating Code For New Versions of Python<br>
+----------------------------------------<br>
+<br>
+Warnings that are only of interest to the developer are ignored by default. As<br>
+such you should make sure to test your code with typically ignored warnings<br>
+made visible. You can do this from the command-line by passing :option:`-Wd`<br>
+to the interpreter (this is shorthand for :option:`-W default`). Â This enables<br>
+default handling for all warnings, including those that are ignored by default.<br>
+To change what action is taken for encountered warnings you simply change what<br>
+argument is passed to :option:`-W`, e.g. :option:`-W error`. See the<br>
+:option:`-W` flag for more details on what is possible.<br>
+<br>
+To programmatically do the same as :option:`-Wd`, use::<br>
+<br>
+ Â warnings.simplefilter(&#39;default&#39;)<br>
+<br>
+Make sure to execute this code as soon as possible. This prevents the<br>
+registering of what warnings have been raised from unexpectedly influencing how<br>
+future warnings are treated.<br>
+<br>
+Having certain warnings ignored by default is done to prevent a user from<br>
+seeing warnings that are only of interest to the developer. As you do not<br>
+necessarily have control over what interpreter a user uses to run their code,<br>
+it is possible that a new version of Python will be released between your<br>
+release cycles. Â The new interpreter release could trigger new warnings in your<br>
+code that were not there in an older interpreter, e.g.<br>
+:exc:`DeprecationWarning` for a module that you are using. While you as a<br>
+developer want to be notified that your code is using a deprecated module, to a<br>
+user this information is essentially noise and provides no benefit to them.<br>
+<br>
+<br>
 .. _warning-functions:<br>
<br>
 Available Functions<br>
<br>
Modified: python/trunk/Lib/test/test_ascii_formatd.py<br>
==============================================================================<br>
--- python/trunk/Lib/test/test_ascii_formatd.py (original)<br>
+++ python/trunk/Lib/test/test_ascii_formatd.py Sun Jan 10 03:56:19 2010<br>
@@ -4,6 +4,7 @@<br>
<br>
 import unittest<br>
 from test_support import check_warnings, run_unittest, cpython_only<br>
+import warnings<br>
<br>
<br>
 class FormatDeprecationTests(unittest.TestCase):<br>
@@ -17,6 +18,7 @@<br>
 Â  Â  Â  Â  buf = create_string_buffer(&#39; &#39; * 100)<br>
<br>
 Â  Â  Â  Â  with check_warnings() as w:<br>
+ Â  Â  Â  Â  Â  Â warnings.simplefilter(&#39;default&#39;)<br>
 Â  Â  Â  Â  Â  Â  PyOS_ascii_formatd(byref(buf), sizeof(buf), &#39;%+.10f&#39;,<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â c_double(10.0))<br>
 Â  Â  Â  Â  Â  Â  self.assertEqual(buf.value, &#39;+10.0000000000&#39;)<br>
<br>
Modified: python/trunk/Lib/test/test_exceptions.py<br>
==============================================================================<br>
--- python/trunk/Lib/test/test_exceptions.py Â  Â (original)<br>
+++ python/trunk/Lib/test/test_exceptions.py Â  Â Sun Jan 10 03:56:19 2010<br>
@@ -309,6 +309,7 @@<br>
 Â  Â  Â  Â  # BaseException.__init__ triggers a deprecation warning.<br>
 Â  Â  Â  Â  exc = BaseException(&quot;foo&quot;)<br>
 Â  Â  Â  Â  with warnings.catch_warnings(record=True) as w:<br>
+ Â  Â  Â  Â  Â  Â warnings.simplefilter(&#39;default&#39;)<br>
 Â  Â  Â  Â  Â  Â  self.assertEquals(exc.message, &quot;foo&quot;)<br>
 Â  Â  Â  Â  self.assertEquals(len(w), 1)<br>
 Â  Â  Â  Â  self.assertEquals(w[0].category, DeprecationWarning)<br>
<br>
Modified: python/trunk/Lib/warnings.py<br>
==============================================================================<br>
--- python/trunk/Lib/warnings.py Â  Â  Â  Â (original)<br>
+++ python/trunk/Lib/warnings.py Â  Â  Â  Â Sun Jan 10 03:56:19 2010<br>
@@ -383,8 +383,8 @@<br>
 # Module initialization<br>
 _processoptions(sys.warnoptions)<br>
 if not _warnings_defaults:<br>
- Â  Â simplefilter(&quot;ignore&quot;, category=PendingDeprecationWarning, append=1)<br>
- Â  Â simplefilter(&quot;ignore&quot;, category=ImportWarning, append=1)<br>
+ Â  Â for cls in (DeprecationWarning, PendingDeprecationWarning, ImportWarning):<br>
+ Â  Â  Â  Â simplefilter(&quot;ignore&quot;, category=cls, append=True)<br>
 Â  Â  bytes_warning = sys.flags.bytes_warning<br>
 Â  Â  if bytes_warning &gt; 1:<br>
 Â  Â  Â  Â  bytes_action = &quot;error&quot;<br>
<br>
Modified: python/trunk/Misc/NEWS<br>
==============================================================================<br>
--- python/trunk/Misc/NEWS Â  Â  Â (original)<br>
+++ python/trunk/Misc/NEWS Â  Â  Â Sun Jan 10 03:56:19 2010<br>
@@ -12,6 +12,8 @@<br>
 Core and Builtins<br>
 -----------------<br>
<br>
+- Issue #7319: Silence DeprecationWarning by default.<br>
+<br>
 - Issue #2335: Backport set literals syntax from Python 3.x.<br>
<br>
 Library<br>
<br>
Modified: python/trunk/Python/_warnings.c<br>
==============================================================================<br>
--- python/trunk/Python/_warnings.c Â  Â  (original)<br>
+++ python/trunk/Python/_warnings.c Â  Â  Sun Jan 10 03:56:19 2010<br>
@@ -85,10 +85,10 @@<br>
<br>
 Â  Â  default_action = get_warnings_attr(&quot;defaultaction&quot;);<br>
 Â  Â  if (default_action == NULL) {<br>
- Â  Â  Â  if (PyErr_Occurred()) {<br>
- Â  Â  Â  Â  Â  return NULL;<br>
- Â  Â  Â  }<br>
- Â  Â  Â  return _default_action;<br>
+ Â  Â  Â  Â if (PyErr_Occurred()) {<br>
+ Â  Â  Â  Â  Â  Â return NULL;<br>
+ Â  Â  Â  Â }<br>
+ Â  Â  Â  Â return _default_action;<br>
 Â  Â  }<br>
<br>
 Â  Â  Py_DECREF(_default_action);<br>
@@ -202,12 +202,12 @@<br>
<br>
 Â  Â  mod_str = PyString_AsString(filename);<br>
 Â  Â  if (mod_str == NULL)<br>
- Â  Â  Â  Â  Â  return NULL;<br>
+ Â  Â  Â  Â return NULL;<br>
 Â  Â  len = PyString_Size(filename);<br>
 Â  Â  if (len &lt; 0)<br>
 Â  Â  Â  Â  return NULL;<br>
 Â  Â  if (len &gt;= 3 &amp;&amp;<br>
- Â  Â  Â  strncmp(mod_str + (len - 3), &quot;.py&quot;, 3) == 0) {<br>
+ Â  Â  Â  Â  Â  Â strncmp(mod_str + (len - 3), &quot;.py&quot;, 3) == 0) {<br>
 Â  Â  Â  Â  module = PyString_FromStringAndSize(mod_str, len-3);<br>
 Â  Â  }<br>
 Â  Â  else {<br>
@@ -251,7 +251,7 @@<br>
<br>
 Â  Â  name = PyObject_GetAttrString(category, &quot;__name__&quot;);<br>
 Â  Â  if (name == NULL) Â /* XXX Can an object lack a &#39;__name__&#39; attribute? */<br>
- Â  Â  Â  Â  Â  return;<br>
+ Â  Â  Â  Â return;<br>
<br>
 Â  Â  f_stderr = PySys_GetObject(&quot;stderr&quot;);<br>
 Â  Â  if (f_stderr == NULL) {<br>
@@ -341,7 +341,7 @@<br>
 Â  Â  Â  Â  rc = already_warned(registry, key, 0);<br>
 Â  Â  Â  Â  if (rc == -1)<br>
 Â  Â  Â  Â  Â  Â  goto cleanup;<br>
- Â  Â  Â  else if (rc == 1)<br>
+ Â  Â  Â  Â else if (rc == 1)<br>
 Â  Â  Â  Â  Â  Â  goto return_none;<br>
 Â  Â  Â  Â  /* Else this warning hasn&#39;t been generated before. */<br>
 Â  Â  }<br>
@@ -492,9 +492,9 @@<br>
 Â  Â  /* Setup filename. */<br>
 Â  Â  *filename = PyDict_GetItemString(globals, &quot;__file__&quot;);<br>
 Â  Â  if (*filename != NULL) {<br>
- Â  Â  Â  Â  Â  Py_ssize_t len = PyString_Size(*filename);<br>
+ Â  Â  Â  Â  Â  Â Py_ssize_t len = PyString_Size(*filename);<br>
 Â  Â  Â  Â  const char *file_str = PyString_AsString(*filename);<br>
- Â  Â  Â  Â  Â  if (file_str == NULL || (len &lt; 0 &amp;&amp; PyErr_Occurred()))<br>
+ Â  Â  Â  Â  Â  Â if (file_str == NULL || (len &lt; 0 &amp;&amp; PyErr_Occurred()))<br>
 Â  Â  Â  Â  Â  Â  goto handle_error;<br>
<br>
 Â  Â  Â  Â  /* if filename.lower().endswith((&quot;.pyc&quot;, &quot;.pyo&quot;)): */<br>
@@ -506,10 +506,10 @@<br>
 Â  Â  Â  Â  Â  Â  Â  Â  tolower(file_str[len-1]) == &#39;o&#39;))<br>
 Â  Â  Â  Â  {<br>
 Â  Â  Â  Â  Â  Â  *filename = PyString_FromStringAndSize(file_str, len-1);<br>
- Â  Â  Â  Â  Â  Â  Â  if (*filename == NULL)<br>
- Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  goto handle_error;<br>
- Â  Â  Â  Â  Â  }<br>
- Â  Â  Â  Â  Â  else<br>
+ Â  Â  Â  Â  Â  Â if (*filename == NULL)<br>
+ Â  Â  Â  Â  Â  Â  Â  Â goto handle_error;<br>
+ Â  Â  Â  Â }<br>
+ Â  Â  Â  Â else<br>
 Â  Â  Â  Â  Â  Â  Py_INCREF(*filename);<br>
 Â  Â  }<br>
 Â  Â  else {<br>
@@ -536,8 +536,8 @@<br>
 Â  Â  Â  Â  Â  Â  else {<br>
 Â  Â  Â  Â  Â  Â  Â  Â  /* embedded interpreters don&#39;t have sys.argv, see bug #839151 */<br>
 Â  Â  Â  Â  Â  Â  Â  Â  *filename = PyString_FromString(&quot;__main__&quot;);<br>
- Â  Â  Â  Â  Â  Â  Â  Â  Â  if (*filename == NULL)<br>
- Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  goto handle_error;<br>
+ Â  Â  Â  Â  Â  Â  Â  Â if (*filename == NULL)<br>
+ Â  Â  Â  Â  Â  Â  Â  Â  Â  Â goto handle_error;<br>
 Â  Â  Â  Â  Â  Â  }<br>
 Â  Â  Â  Â  }<br>
 Â  Â  Â  Â  if (*filename == NULL) {<br>
@@ -839,26 +839,29 @@<br>
 static PyObject *<br>
 init_filters(void)<br>
 {<br>
- Â  Â PyObject *filters = PyList_New(3);<br>
+ Â  Â PyObject *filters = PyList_New(4);<br>
 Â  Â  const char *bytes_action;<br>
 Â  Â  if (filters == NULL)<br>
 Â  Â  Â  Â  return NULL;<br>
<br>
 Â  Â  PyList_SET_ITEM(filters, 0,<br>
+ Â  Â  Â  Â  Â  Â  Â  Â  Â  Â create_filter(PyExc_DeprecationWarning, &quot;ignore&quot;));<br>
+ Â  Â PyList_SET_ITEM(filters, 1,<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  create_filter(PyExc_PendingDeprecationWarning, &quot;ignore&quot;));<br>
- Â  Â PyList_SET_ITEM(filters, 1, create_filter(PyExc_ImportWarning, &quot;ignore&quot;));<br>
+ Â  Â PyList_SET_ITEM(filters, 2, create_filter(PyExc_ImportWarning, &quot;ignore&quot;));<br>
 Â  Â  if (Py_BytesWarningFlag &gt; 1)<br>
 Â  Â  Â  Â  bytes_action = &quot;error&quot;;<br>
 Â  Â  else if (Py_BytesWarningFlag)<br>
 Â  Â  Â  Â  bytes_action = &quot;default&quot;;<br>
 Â  Â  else<br>
 Â  Â  Â  Â  bytes_action = &quot;ignore&quot;;<br>
- Â  Â PyList_SET_ITEM(filters, 2, create_filter(PyExc_BytesWarning,<br>
+ Â  Â PyList_SET_ITEM(filters, 3, create_filter(PyExc_BytesWarning,<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  bytes_action));<br>
<br>
 Â  Â  if (PyList_GET_ITEM(filters, 0) == NULL ||<br>
 Â  Â  Â  Â  PyList_GET_ITEM(filters, 1) == NULL ||<br>
- Â  Â  Â  Â PyList_GET_ITEM(filters, 2) == NULL) {<br>
+ Â  Â  Â  Â PyList_GET_ITEM(filters, 2) == NULL ||<br>
+ Â  Â  Â  Â PyList_GET_ITEM(filters, 3) == NULL) {<br>
 Â  Â  Â  Â  Py_DECREF(filters);<br>
 Â  Â  Â  Â  return NULL;<br>
<div><div></div><div class="h5"> Â  Â  }<br>
_______________________________________________<br>
Python-checkins mailing list<br>
<a href="mailto:Python-checkins@python.org">Python-checkins@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-checkins" target="_blank">http://mail.python.org/mailman/listinfo/python-checkins</a><br>
</div></div></div><br>

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