Skip to content

Commit aea2c0a

Browse files
author
georg.brandl
committed
Make Py3k warnings consistent w.r.t. punctuation; also respect the
EOL 80 limit and supply more alternatives in warning messages. git-svn-id: http://svn.python.org/projects/python/trunk@61879 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 853a751 commit aea2c0a

16 files changed

Lines changed: 67 additions & 54 deletions

File tree

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ A new command-line switch, :option:`-3`, enables warnings
9393
about features that will be removed in Python 3.0. You can run code
9494
with this switch to see how much work will be necessary to port
9595
code to 3.0. The value of this switch is available
96-
to Python code as the boolean variable ``sys.py3kwarning``,
96+
to Python code as the boolean variable :data:`sys.py3kwarning`,
9797
and to C extension code as :cdata:`Py_Py3kWarningFlag`.
9898

9999
Python 3.0 adds several new built-in functions and change the

Lib/test/test_py3kwarn.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
class TestPy3KWarnings(unittest.TestCase):
1212

1313
def test_type_inequality_comparisons(self):
14-
expected = 'type inequality comparisons not supported in 3.x.'
14+
expected = 'type inequality comparisons not supported in 3.x'
1515
with catch_warning() as w:
1616
self.assertWarning(int < str, w, expected)
1717
with catch_warning() as w:
1818
self.assertWarning(type < object, w, expected)
1919

2020
def test_object_inequality_comparisons(self):
21-
expected = 'comparing unequal types not supported in 3.x.'
21+
expected = 'comparing unequal types not supported in 3.x'
2222
with catch_warning() as w:
2323
self.assertWarning(str < [], w, expected)
2424
with catch_warning() as w:
2525
self.assertWarning(object() < (1, 2), w, expected)
2626

2727
def test_dict_inequality_comparisons(self):
28-
expected = 'dict inequality comparisons not supported in 3.x.'
28+
expected = 'dict inequality comparisons not supported in 3.x'
2929
with catch_warning() as w:
3030
self.assertWarning({} < {2:3}, w, expected)
3131
with catch_warning() as w:
@@ -36,7 +36,7 @@ def test_dict_inequality_comparisons(self):
3636
self.assertWarning({2:3} >= {}, w, expected)
3737

3838
def test_cell_inequality_comparisons(self):
39-
expected = 'cell comparisons not supported in 3.x.'
39+
expected = 'cell comparisons not supported in 3.x'
4040
def f(x):
4141
def g():
4242
return x
@@ -49,7 +49,7 @@ def g():
4949
self.assertWarning(cell0 < cell1, w, expected)
5050

5151
def test_code_inequality_comparisons(self):
52-
expected = 'code inequality comparisons not supported in 3.x.'
52+
expected = 'code inequality comparisons not supported in 3.x'
5353
def f(x):
5454
pass
5555
def g(x):
@@ -65,7 +65,7 @@ def g(x):
6565

6666
def test_builtin_function_or_method_comparisons(self):
6767
expected = ('builtin_function_or_method '
68-
'inequality comparisons not supported in 3.x.')
68+
'inequality comparisons not supported in 3.x')
6969
func = eval
7070
meth = {}.get
7171
with catch_warning() as w:
@@ -81,7 +81,7 @@ def assertWarning(self, _, warning, expected_message):
8181
self.assertEqual(str(warning.message), expected_message)
8282

8383
def test_sort_cmp_arg(self):
84-
expected = "In 3.x, the cmp argument is no longer supported."
84+
expected = "the cmp argument is not supported in 3.x"
8585
lst = range(5)
8686
cmp = lambda x,y: -1
8787

@@ -95,7 +95,7 @@ def test_sort_cmp_arg(self):
9595
self.assertWarning(sorted(lst, cmp), w, expected)
9696

9797
def test_sys_exc_clear(self):
98-
expected = 'sys.exc_clear() not supported in 3.x. Use except clauses.'
98+
expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
9999
with catch_warning() as w:
100100
self.assertWarning(sys.exc_clear(), w, expected)
101101

@@ -119,7 +119,7 @@ def set():
119119
self.assertWarning(set(), w, expected)
120120

121121
def test_buffer(self):
122-
expected = 'buffer will be removed in 3.x'
122+
expected = 'buffer() not supported in 3.x; use memoryview()'
123123
with catch_warning() as w:
124124
self.assertWarning(buffer('a'), w, expected)
125125

Objects/bufferobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
231231
{
232232
if (Py_Py3kWarningFlag &&
233233
PyErr_WarnEx(PyExc_DeprecationWarning,
234-
"buffer will be removed in 3.x", 1) < 0)
234+
"buffer() not supported in 3.x; "
235+
"use memoryview()", 1) < 0)
235236
return NULL;
236237

237238
PyObject *ob;

Objects/cellobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ static int
5555
cell_compare(PyCellObject *a, PyCellObject *b)
5656
{
5757
/* Py3K warning for comparisons */
58-
if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
59-
"cell comparisons not supported in 3.x.") < 0) {
58+
if (Py_Py3kWarningFlag &&
59+
PyErr_Warn(PyExc_DeprecationWarning,
60+
"cell comparisons not supported in 3.x") < 0) {
6061
return -2;
6162
}
6263

Objects/codeobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ code_richcompare(PyObject *self, PyObject *other, int op)
338338
!PyCode_Check(self) ||
339339
!PyCode_Check(other)) {
340340

341-
/* Py3K warning if types are not equal and comparison isn't == or != */
342-
if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
343-
"code inequality comparisons not supported in 3.x.") < 0) {
341+
/* Py3K warning if types are not equal and comparison
342+
isn't == or != */
343+
if (Py_Py3kWarningFlag &&
344+
PyErr_Warn(PyExc_DeprecationWarning,
345+
"code inequality comparisons not supported "
346+
"in 3.x") < 0) {
344347
return NULL;
345348
}
346349

Objects/dictobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,10 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
17781778
}
17791779
else {
17801780
/* Py3K warning if comparison isn't == or != */
1781-
if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
1782-
"dict inequality comparisons not supported in 3.x.") < 0) {
1781+
if (Py_Py3kWarningFlag &&
1782+
PyErr_Warn(PyExc_DeprecationWarning,
1783+
"dict inequality comparisons not supported "
1784+
"in 3.x") < 0) {
17831785
return NULL;
17841786
}
17851787
res = Py_NotImplemented;
@@ -1811,7 +1813,8 @@ dict_has_key(register PyDictObject *mp, PyObject *key)
18111813
{
18121814
if (Py_Py3kWarningFlag &&
18131815
PyErr_Warn(PyExc_DeprecationWarning,
1814-
"dict.has_key() not supported in 3.x") < 0)
1816+
"dict.has_key() not supported in 3.x; "
1817+
"use the in operator") < 0)
18151818
return NULL;
18161819
return dict_contains(mp, key);
18171820
}

Objects/exceptions.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ static PyObject *
190190
BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
191191
{
192192
if (Py_Py3kWarningFlag) {
193-
if (PyErr_Warn(PyExc_DeprecationWarning,
194-
"In 3.x, __getitem__ is not supported for exception "
195-
"classes, use args attribute") == -1)
196-
return NULL;
193+
if (PyErr_Warn(PyExc_DeprecationWarning,
194+
"__getitem__ not supported for exception "
195+
"classes in 3.x; use args attribute") == -1)
196+
return NULL;
197197
}
198198
return PySequence_GetItem(self->args, index);
199199
}
@@ -203,10 +203,10 @@ BaseException_getslice(PyBaseExceptionObject *self,
203203
Py_ssize_t start, Py_ssize_t stop)
204204
{
205205
if (Py_Py3kWarningFlag) {
206-
if (PyErr_Warn(PyExc_DeprecationWarning,
207-
"In 3.x, __getslice__ is not supported for exception "
208-
"classes, use args attribute") == -1)
209-
return NULL;
206+
if (PyErr_Warn(PyExc_DeprecationWarning,
207+
"__getslice__ not supported for exception "
208+
"classes in 3.x; use args attribute") == -1)
209+
return NULL;
210210
}
211211
return PySequence_GetSlice(self->args, start, stop);
212212
}

Objects/listobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
20402040
if (compare != NULL &&
20412041
Py_Py3kWarningFlag &&
20422042
PyErr_Warn(PyExc_DeprecationWarning,
2043-
"In 3.x, the cmp argument is no longer supported.") < 0)
2043+
"the cmp argument is not supported in 3.x") < 0)
20442044
return NULL;
20452045
if (keyfunc == Py_None)
20462046
keyfunc = NULL;

Objects/methodobject.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
235235
!PyCFunction_Check(other))
236236
{
237237
/* Py3K warning if types are not equal and comparison isn't == or != */
238-
if (Py_Py3kWarningFlag && PyErr_Warn(PyExc_DeprecationWarning,
239-
"builtin_function_or_method "
240-
"inequality comparisons not supported in 3.x.") < 0) {
238+
if (Py_Py3kWarningFlag &&
239+
PyErr_Warn(PyExc_DeprecationWarning,
240+
"builtin_function_or_method inequality "
241+
"comparisons not supported in 3.x") < 0) {
241242
return NULL;
242243
}
243244

@@ -353,12 +354,10 @@ Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
353354
{
354355
if (name[0] == '_' && name[1] == '_') {
355356
if (strcmp(name, "__methods__") == 0) {
356-
if (Py_Py3kWarningFlag) {
357-
if (PyErr_Warn(PyExc_DeprecationWarning,
358-
"__methods__ not supported "
359-
"in 3.x") < 0)
360-
return NULL;
361-
}
357+
if (Py_Py3kWarningFlag &&
358+
PyErr_Warn(PyExc_DeprecationWarning,
359+
"__methods__ not supported in 3.x") < 0)
360+
return NULL;
362361
return listmethodchain(chain);
363362
}
364363
if (strcmp(name, "__doc__") == 0) {

Objects/object.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,10 @@ try_3way_to_rich_compare(PyObject *v, PyObject *w, int op)
867867

868868
/* Py3K warning if types are not equal and comparison isn't == or != */
869869
if (Py_Py3kWarningFlag &&
870-
v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
871-
PyErr_Warn(PyExc_DeprecationWarning,
872-
"comparing unequal types not supported in 3.x.") < 0) {
870+
v->ob_type != w->ob_type && op != Py_EQ && op != Py_NE &&
871+
PyErr_Warn(PyExc_DeprecationWarning,
872+
"comparing unequal types not supported "
873+
"in 3.x") < 0) {
873874
return NULL;
874875
}
875876

@@ -1691,8 +1692,8 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
16911692
(strcmp(attrname, "__members__") == 0 ||
16921693
strcmp(attrname, "__methods__") == 0)) {
16931694
if (PyErr_Warn(PyExc_DeprecationWarning,
1694-
"__members__ and __methods__ not supported "
1695-
"in 3.x") < 0) {
1695+
"__members__ and __methods__ not "
1696+
"supported in 3.x") < 0) {
16961697
Py_XDECREF(list);
16971698
return -1;
16981699
}

0 commit comments

Comments
 (0)