]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make Py3k warnings consistent w.r.t. punctuation; also respect the
authorGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 08:29:14 +0000 (08:29 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 25 Mar 2008 08:29:14 +0000 (08:29 +0000)
EOL 80 limit and supply more alternatives in warning messages.

16 files changed:
Doc/whatsnew/2.6.rst
Lib/test/test_py3kwarn.py
Objects/bufferobject.c
Objects/cellobject.c
Objects/codeobject.c
Objects/dictobject.c
Objects/exceptions.c
Objects/listobject.c
Objects/methodobject.c
Objects/object.c
Objects/typeobject.c
Parser/tokenizer.c
Python/ast.c
Python/bltinmodule.c
Python/ceval.c
Python/sysmodule.c

index 0e8901b4c72ead0d7d005fca11e8981c4151064a..d255c16f9024d0add0775d8217715d3928cf940d 100644 (file)
@@ -93,7 +93,7 @@ A new command-line switch, :option:`-3`, enables warnings
 about features that will be removed in Python 3.0.  You can run code
 with this switch to see how much work will be necessary to port
 code to 3.0.  The value of this switch is available 
-to Python code as the boolean variable ``sys.py3kwarning``,
+to Python code as the boolean variable :data:`sys.py3kwarning`,
 and to C extension code as :cdata:`Py_Py3kWarningFlag`.
 
 Python 3.0 adds several new built-in functions and change the
index 41ad25bdf7461a299cf7010e6770344ad7e79b97..5766e61079cb0819e8c2dfac919dfbf9d007c6b2 100644 (file)
@@ -11,21 +11,21 @@ if not sys.py3kwarning:
 class TestPy3KWarnings(unittest.TestCase):
 
     def test_type_inequality_comparisons(self):
-        expected = 'type inequality comparisons not supported in 3.x.'
+        expected = 'type inequality comparisons not supported in 3.x'
         with catch_warning() as w:
             self.assertWarning(int < str, w, expected)
         with catch_warning() as w:
             self.assertWarning(type < object, w, expected)
 
     def test_object_inequality_comparisons(self):
-        expected = 'comparing unequal types not supported in 3.x.'
+        expected = 'comparing unequal types not supported in 3.x'
         with catch_warning() as w:
             self.assertWarning(str < [], w, expected)
         with catch_warning() as w:
             self.assertWarning(object() < (1, 2), w, expected)
 
     def test_dict_inequality_comparisons(self):
-        expected = 'dict inequality comparisons not supported in 3.x.'
+        expected = 'dict inequality comparisons not supported in 3.x'
         with catch_warning() as w:
             self.assertWarning({} < {2:3}, w, expected)
         with catch_warning() as w:
@@ -36,7 +36,7 @@ class TestPy3KWarnings(unittest.TestCase):
             self.assertWarning({2:3} >= {}, w, expected)
 
     def test_cell_inequality_comparisons(self):
-        expected = 'cell comparisons not supported in 3.x.'
+        expected = 'cell comparisons not supported in 3.x'
         def f(x):
             def g():
                 return x
@@ -49,7 +49,7 @@ class TestPy3KWarnings(unittest.TestCase):
             self.assertWarning(cell0 < cell1, w, expected)
 
     def test_code_inequality_comparisons(self):
-        expected = 'code inequality comparisons not supported in 3.x.'
+        expected = 'code inequality comparisons not supported in 3.x'
         def f(x):
             pass
         def g(x):
@@ -65,7 +65,7 @@ class TestPy3KWarnings(unittest.TestCase):
 
     def test_builtin_function_or_method_comparisons(self):
         expected = ('builtin_function_or_method '
-                    'inequality comparisons not supported in 3.x.')
+                    'inequality comparisons not supported in 3.x')
         func = eval
         meth = {}.get
         with catch_warning() as w:
@@ -81,7 +81,7 @@ class TestPy3KWarnings(unittest.TestCase):
         self.assertEqual(str(warning.message), expected_message)
 
     def test_sort_cmp_arg(self):
-        expected = "In 3.x, the cmp argument is no longer supported."
+        expected = "the cmp argument is not supported in 3.x"
         lst = range(5)
         cmp = lambda x,y: -1
 
@@ -95,7 +95,7 @@ class TestPy3KWarnings(unittest.TestCase):
             self.assertWarning(sorted(lst, cmp), w, expected)
 
     def test_sys_exc_clear(self):
-        expected = 'sys.exc_clear() not supported in 3.x. Use except clauses.'
+        expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
         with catch_warning() as w:
             self.assertWarning(sys.exc_clear(), w, expected)
 
@@ -119,7 +119,7 @@ class TestPy3KWarnings(unittest.TestCase):
                 self.assertWarning(set(), w, expected)
 
     def test_buffer(self):
-        expected = 'buffer will be removed in 3.x'
+        expected = 'buffer() not supported in 3.x; use memoryview()'
         with catch_warning() as w:
             self.assertWarning(buffer('a'), w, expected)
 
index 0a818d634c15dfc2e29554894ae9eeb37c08ec49..fb7e1ef0131f9901da957cee7b4f4d8ad82326c1 100644 (file)
@@ -231,7 +231,8 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
 {
        if (Py_Py3kWarningFlag &&
            PyErr_WarnEx(PyExc_DeprecationWarning,
-           "buffer will be removed in 3.x", 1) < 0)
+                        "buffer() not supported in 3.x; "
+                        "use memoryview()", 1) < 0)
                return NULL;
        
        PyObject *ob;
index 2286aafc2b1e1dbe83e32be0c3aacc534c44c4dd..b86739edb3295070eadaedd8e3b4a44858876685 100644 (file)
@@ -55,8 +55,9 @@ static int
 cell_compare(PyCellObject *a, PyCellObject *b)
 {
        /* Py3K warning for comparisons  */
-       if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
-                       "cell comparisons not supported in 3.x.") < 0) {
+       if (Py_Py3kWarningFlag &&
+            PyErr_Warn(PyExc_DeprecationWarning,
+                      "cell comparisons not supported in 3.x") < 0) {
                return -2;
        }
 
index 57cd2e626448f5c45400b8cb48175667411d8b24..33b4610c743b210eb1fe00e571e6cb50f3c02d6d 100644 (file)
@@ -338,9 +338,12 @@ code_richcompare(PyObject *self, PyObject *other, int op)
            !PyCode_Check(self) ||
            !PyCode_Check(other)) {
 
-               /* Py3K warning if types are not equal and comparison isn't == or !=  */
-               if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
-                               "code inequality comparisons not supported in 3.x.") < 0) {
+               /* Py3K warning if types are not equal and comparison
+                   isn't == or !=  */
+               if (Py_Py3kWarningFlag &&
+                   PyErr_Warn(PyExc_DeprecationWarning,
+                              "code inequality comparisons not supported "
+                              "in 3.x") < 0) {
                        return NULL;
                }
 
index 1ca28303c74a6221d866c086ca5ca0a80983ee2e..b8971180a4986e1a11fa0e816fa7838cffde10ff 100644 (file)
@@ -1778,8 +1778,10 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
        }
        else {
                /* Py3K warning if comparison isn't == or !=  */
-               if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
-                               "dict inequality comparisons not supported in 3.x.") < 0) {
+               if (Py_Py3kWarningFlag &&
+                    PyErr_Warn(PyExc_DeprecationWarning,
+                              "dict inequality comparisons not supported "
+                              "in 3.x") < 0) {
                        return NULL;
                }
                res = Py_NotImplemented;
@@ -1811,7 +1813,8 @@ dict_has_key(register PyDictObject *mp, PyObject *key)
 {
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "dict.has_key() not supported in 3.x") < 0)
+                      "dict.has_key() not supported in 3.x; "
+                      "use the in operator") < 0)
                return NULL;
        return dict_contains(mp, key);
 }
index 7fecb35cbf4648464d2abfdb1067d49f12a8f827..ec17bc23a4acf5beb93940ba0d6483ce3f44260f 100644 (file)
@@ -190,10 +190,10 @@ static PyObject *
 BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
 {
     if (Py_Py3kWarningFlag) {
-       if (PyErr_Warn(PyExc_DeprecationWarning,
-                      "In 3.x, __getitem__ is not supported for exception "
-                      "classes, use args attribute") == -1)
-           return NULL;
+        if (PyErr_Warn(PyExc_DeprecationWarning,
+                       "__getitem__ not supported for exception "
+                       "classes in 3.x; use args attribute") == -1)
+            return NULL;
     }
     return PySequence_GetItem(self->args, index);
 }
@@ -203,10 +203,10 @@ BaseException_getslice(PyBaseExceptionObject *self,
                        Py_ssize_t start, Py_ssize_t stop)
 {
     if (Py_Py3kWarningFlag) {
-       if (PyErr_Warn(PyExc_DeprecationWarning,
-                      "In 3.x, __getslice__ is not supported for exception "
-                      "classes, use args attribute") == -1)
-           return NULL;
+        if (PyErr_Warn(PyExc_DeprecationWarning,
+                       "__getslice__ not supported for exception "
+                       "classes in 3.x; use args attribute") == -1)
+            return NULL;
     }
     return PySequence_GetSlice(self->args, start, stop);
 }
index d4faf0a15e46f86033688b40c016e6c79d2234f6..81617e44cb4523021e2978fa7117a1bbc50e9203 100644 (file)
@@ -2040,7 +2040,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
        if (compare != NULL && 
             Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "In 3.x, the cmp argument is no longer supported.") < 0)
+                      "the cmp argument is not supported in 3.x") < 0)
                return NULL;
        if (keyfunc == Py_None)
                keyfunc = NULL;
index 16175f9e98c8fd7bdd3bd898b579a0ab52c1688c..e641df12fed96d2cda98e9f37879c23c379b3405 100644 (file)
@@ -235,9 +235,10 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
            !PyCFunction_Check(other))
        {
                /* Py3K warning if types are not equal and comparison isn't == or !=  */
-               if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
-                               "builtin_function_or_method "
-                               "inequality comparisons not supported in 3.x.") < 0) {
+               if (Py_Py3kWarningFlag &&
+                   PyErr_Warn(PyExc_DeprecationWarning,
+                              "builtin_function_or_method inequality "
+                              "comparisons not supported in 3.x") < 0) {
                        return NULL;
                }
 
@@ -353,12 +354,10 @@ Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
 {
        if (name[0] == '_' && name[1] == '_') {
                if (strcmp(name, "__methods__") == 0) {
-                       if (Py_Py3kWarningFlag) {
-                               if (PyErr_Warn(PyExc_DeprecationWarning,
-                                              "__methods__ not supported "
-                                              "in 3.x") < 0)
-                                       return NULL;
-                       }
+                       if (Py_Py3kWarningFlag &&
+                           PyErr_Warn(PyExc_DeprecationWarning,
+                                      "__methods__ not supported in 3.x") < 0)
+                               return NULL;
                        return listmethodchain(chain);
                }
                if (strcmp(name, "__doc__") == 0) {
index 4a66f4fee147ee8a7289a0522e4a9c220b3d3eea..e3377f3a6f967577365d1c29f38faf3757097bfe 100644 (file)
@@ -867,9 +867,10 @@ try_3way_to_rich_compare(PyObject *v, PyObject *w, int op)
 
                /* Py3K warning if types are not equal and comparison isn't == or !=  */
                if (Py_Py3kWarningFlag &&
-                       v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
-                       PyErr_Warn(PyExc_DeprecationWarning,
-                               "comparing unequal types not supported in 3.x.") < 0) {
+                   v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
+                   PyErr_Warn(PyExc_DeprecationWarning,
+                              "comparing unequal types not supported "
+                              "in 3.x") < 0) {
                        return NULL;
                }
 
@@ -1691,8 +1692,8 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
                    (strcmp(attrname, "__members__") == 0 ||
                     strcmp(attrname, "__methods__") == 0)) {
                        if (PyErr_Warn(PyExc_DeprecationWarning, 
-                                      "__members__ and __methods__ not supported "
-                                      "in 3.x") < 0) {
+                                      "__members__ and __methods__ not "
+                                      "supported in 3.x") < 0) {
                                Py_XDECREF(list);
                                return -1;
                        }
index 82ced39b30baa7e7ff754de11c3ebfc407252b0e..214e60139fc11fa6ba21288a07df9994564f62ee 100644 (file)
@@ -609,7 +609,8 @@ type_richcompare(PyObject *v, PyObject *w, int op)
        /* Py3K warning if comparison isn't == or !=  */
        if (Py_Py3kWarningFlag && op != Py_EQ && op != Py_NE &&
                PyErr_Warn(PyExc_DeprecationWarning,
-                       "type inequality comparisons not supported in 3.x.") < 0) {
+                          "type inequality comparisons not supported "
+                          "in 3.x") < 0) {
                return NULL;
        }
 
index 6df300503ffdf2414288b42f68983b99008bf1d3..799db20543fc5421e02e98a899d07b2f842724d1 100644 (file)
@@ -1531,7 +1531,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
 #ifndef PGEN
                if (Py_Py3kWarningFlag && token == NOTEQUAL && c == '<') {
                        if (PyErr_WarnExplicit(PyExc_DeprecationWarning,
-                                              "<> not supported in 3.x",
+                                              "<> not supported in 3.x; use !=",
                                               tok->filename, tok->lineno,
                                               NULL, NULL)) {
                                return ERRORTOKEN;
index 8a317b880dcc30f594938ea7f4294f04a74a3087..1fc2324830d93f8328572e9635550a1e949e7b1d 100644 (file)
@@ -1363,7 +1363,7 @@ ast_for_atom(struct compiling *c, const node *n)
         expr_ty expression;
         if (Py_Py3kWarningFlag) {
             if (PyErr_WarnExplicit(PyExc_DeprecationWarning,
-                                   "backquote not supported in 3.x",
+                                   "backquote not supported in 3.x; use repr()",
                                    c->c_filename, LINENO(n),
                                    NULL, NULL)) {
             return NULL;
index 3956bb55ef8a11e9291de58ed97b1b0fe5e508c2..c760dcb3cbb649e6fc70387dc0fa7a34c3a030df 100644 (file)
@@ -166,7 +166,8 @@ builtin_apply(PyObject *self, PyObject *args)
 
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "apply() not supported in 3.x. Use func(*args, **kwargs).") < 0)
+                      "apply() not supported in 3.x; "
+                      "use func(*args, **kwargs)") < 0)
                return NULL;
 
        if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))
@@ -225,7 +226,8 @@ builtin_callable(PyObject *self, PyObject *v)
 {
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "callable() not supported in 3.x. Use hasattr(o, '__call__').") < 0)
+                      "callable() not supported in 3.x; "
+                      "use hasattr(o, '__call__')") < 0)
                return NULL;
        return PyBool_FromLong((long)PyCallable_Check(v));
 }
@@ -684,7 +686,7 @@ builtin_execfile(PyObject *self, PyObject *args)
 
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "execfile() not supported in 3.x.  Use exec().") < 0)
+                      "execfile() not supported in 3.x; use exec()") < 0)
                return NULL;
 
        if (!PyArg_ParseTuple(args, "s|O!O:execfile",
@@ -912,7 +914,8 @@ builtin_map(PyObject *self, PyObject *args)
        if (func == Py_None) {
                if (Py_Py3kWarningFlag &&
                    PyErr_Warn(PyExc_DeprecationWarning, 
-                              "map(None, ...) not supported in 3.x. Use list(...).") < 0)
+                              "map(None, ...) not supported in 3.x; "
+                              "use list(...)") < 0)
                        return NULL;
                if (n == 1) {
                        /* map(None, S) is the same as list(S). */
@@ -1934,7 +1937,8 @@ builtin_reduce(PyObject *self, PyObject *args)
 
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "reduce() not supported in 3.x") < 0)
+                      "reduce() not supported in 3.x; "
+                      "use functools.reduce()") < 0)
                return NULL;
 
        if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result))
@@ -2011,7 +2015,7 @@ builtin_reload(PyObject *self, PyObject *v)
 {
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
-                      "reload() not supported in 3.x") < 0)
+                      "reload() not supported in 3.x; use imp.reload()") < 0)
                return NULL;
 
        return PyImport_ReloadModule(v);
index dc1aa52eec6ea94299a853d2f35c1b2b155aa5b5..7c7116ce41a7a396242c706841e50f6ed705d6fd 100644 (file)
@@ -4056,7 +4056,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
      PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
 
 #define CANNOT_CATCH_MSG "catching classes that don't inherit from " \
-                        "BaseException is not allowed in 3.x."
+                        "BaseException is not allowed in 3.x"
 
 static PyObject *
 cmp_outcome(int op, register PyObject *v, register PyObject *w)
index 89e7e30481171d3ee5ce98c5a4ee859912fd9c4c..e733ceedcb45e7b90ab9307eff170f428bbec936 100644 (file)
@@ -174,8 +174,8 @@ sys_exc_clear(PyObject *self, PyObject *noargs)
 
        if (Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning,
-                      "sys.exc_clear() not supported in 3.x. "
-                      "Use except clauses.") < 0)
+                      "sys.exc_clear() not supported in 3.x; "
+                      "use except clauses") < 0)
                return NULL;
 
        tstate = PyThreadState_GET();