Skip to content

Commit 699b112

Browse files
committed
Update message template
1 parent 51a6c79 commit 699b112

13 files changed

Lines changed: 39 additions & 38 deletions

Lib/test/test_coroutines.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ async def foo():
10081008
return (await Awaitable())
10091009

10101010
with self.assertRaisesRegex(
1011-
TypeError, "__await__.*must return type iterator of type"):
1011+
TypeError, "__await__.*must return an iterator, not"):
10121012

10131013
run_async(foo())
10141014

@@ -1106,7 +1106,7 @@ async def foo():
11061106
return await Awaitable()
11071107

11081108
with self.assertRaisesRegex(
1109-
TypeError, r"__await__\(\) must return type iterator \(not coroutine\)"):
1109+
TypeError, r"__await__\(\) must return an iterator, not coroutine"):
11101110
run_async(foo())
11111111

11121112
c.close()
@@ -1120,7 +1120,7 @@ async def foo():
11201120
return await Awaitable()
11211121

11221122
with self.assertRaisesRegex(
1123-
TypeError, "__await__.*must return type iterator of type"):
1123+
TypeError, "__await__.*must return an iterator, not"):
11241124

11251125
run_async(foo())
11261126

@@ -2490,7 +2490,7 @@ async def foo():
24902490
return (await future)
24912491

24922492
with self.assertRaisesRegex(
2493-
TypeError, "__await__.*must return type iterator of type 'int'"):
2493+
TypeError, "__await__.*must return an iterator, not int"):
24942494
self.assertEqual(foo().send(None), 1)
24952495

24962496

Lib/test/test_type_annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def check_annotations(self, f):
301301
print(f.__annotations__)
302302

303303
f.__annotate__ = lambda x: 42
304-
with self.assertRaisesRegex(TypeError, r"__annotate__\(\) must return type dict of type 'int'"):
304+
with self.assertRaisesRegex(TypeError, r"__annotate__\(\) must return a dict, not int"):
305305
print(f.__annotations__)
306306

307307
f.__annotate__ = lambda x: {"x": x}

Objects/abstract.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
133133
}
134134
if (!PyLong_Check(result)) {
135135
PyErr_Format(PyExc_TypeError,
136-
"%T.__length_hint__() must return type int (not %T)",
136+
"%T.__length_hint__() must return an int, not %T",
137137
o, result);
138138
Py_DECREF(result);
139139
return -1;
@@ -145,7 +145,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
145145
}
146146
if (res < 0) {
147147
PyErr_Format(PyExc_ValueError,
148-
"%T.__length_hint__() must return positive int", o);
148+
"%T.__length_hint__() must return a positive int", o);
149149
return -1;
150150
}
151151
return res;
@@ -889,7 +889,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
889889

890890
if (result && !PyUnicode_Check(result)) {
891891
PyErr_Format(PyExc_TypeError,
892-
"%T.__format__() must return type str (not %T)",
892+
"%T.__format__() must return a str, not %T",
893893
obj, result);
894894
Py_SETREF(result, NULL);
895895
goto done;
@@ -1423,14 +1423,14 @@ _PyNumber_Index(PyObject *item)
14231423

14241424
if (!PyLong_Check(result)) {
14251425
PyErr_Format(PyExc_TypeError,
1426-
"%T.__index__() must return type int (not %T)",
1426+
"%T.__index__() must return an int, not %T",
14271427
item, result);
14281428
Py_DECREF(result);
14291429
return NULL;
14301430
}
14311431
/* Issue #17576: warn if 'result' not of exact type int. */
14321432
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1433-
"%T.__index__() must return type int (not %T). "
1433+
"%T.__index__() must return an int, not %T. "
14341434
"The ability to return an instance of a strict subclass of int "
14351435
"is deprecated, and may be removed in a future version of Python.",
14361436
item, result)) {
@@ -1533,14 +1533,14 @@ PyNumber_Long(PyObject *o)
15331533

15341534
if (!PyLong_Check(result)) {
15351535
PyErr_Format(PyExc_TypeError,
1536-
"%T.__int__() must return type int (not %T)",
1536+
"%T.__int__() must return an int, not %T",
15371537
o, result);
15381538
Py_DECREF(result);
15391539
return NULL;
15401540
}
15411541
/* Issue #17576: warn if 'result' not of exact type int. */
15421542
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1543-
"%T.__int__() must return type int (not %T). "
1543+
"%T.__int__() must return an int, not %T. "
15441544
"The ability to return an instance of a strict subclass of int "
15451545
"is deprecated, and may be removed in a future version of Python.",
15461546
o, result)) {
@@ -1611,13 +1611,13 @@ PyNumber_Float(PyObject *o)
16111611

16121612
if (!PyFloat_Check(res)) {
16131613
PyErr_Format(PyExc_TypeError,
1614-
"%T.__float__() must return type float (not %T)", o, res);
1614+
"%T.__float__() must return a float, not %T", o, res);
16151615
Py_DECREF(res);
16161616
return NULL;
16171617
}
16181618
/* Issue #26983: warn if 'res' not of exact type float. */
16191619
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
1620-
"%T.__float__() must return type float (not %T). "
1620+
"%T.__float__() must return a float, not %T. "
16211621
"The ability to return an instance of a strict subclass of float "
16221622
"is deprecated, and may be removed in a future version of Python.",
16231623
o, res)) {
@@ -2436,7 +2436,7 @@ method_output_as_list(PyObject *o, PyObject *meth)
24362436
PyThreadState *tstate = _PyThreadState_GET();
24372437
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) {
24382438
_PyErr_Format(tstate, PyExc_TypeError,
2439-
"%T.%U() must return type iterable (not %T)",
2439+
"%T.%U() must return an iterable, not %T",
24402440
o, meth, meth_output);
24412441
}
24422442
Py_DECREF(meth_output);
@@ -2817,7 +2817,7 @@ PyObject_GetIter(PyObject *o)
28172817
PyObject *res = (*f)(o);
28182818
if (res != NULL && !PyIter_Check(res)) {
28192819
PyErr_Format(PyExc_TypeError,
2820-
"%T.iter() must return type iterator of type '%T'",
2820+
"%T.iter() must return an iterator, not %T",
28212821
o, res);
28222822
Py_SETREF(res, NULL);
28232823
}
@@ -2837,7 +2837,7 @@ PyObject_GetAIter(PyObject *o) {
28372837
PyObject *it = (*f)(o);
28382838
if (it != NULL && !PyAIter_Check(it)) {
28392839
PyErr_Format(PyExc_TypeError,
2840-
"%T.aiter() must return type async iterator of type '%T'",
2840+
"%T.aiter() must return an async iterator, not %T",
28412841
o, it);
28422842
Py_SETREF(it, NULL);
28432843
}

Objects/bytesobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
566566
return NULL;
567567
if (!PyBytes_Check(result)) {
568568
PyErr_Format(PyExc_TypeError,
569-
"%T.__bytes__() must return type bytes (not %T)",
569+
"%T.__bytes__() must return a bytes, not %T",
570570
v, result);
571571
Py_DECREF(result);
572572
return NULL;
@@ -2788,7 +2788,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
27882788
return NULL;
27892789
if (!PyBytes_Check(bytes)) {
27902790
PyErr_Format(PyExc_TypeError,
2791-
"%T.__bytes__() must return type bytes (not %T)",
2791+
"%T.__bytes__() must return a bytes, not %T",
27922792
x, bytes);
27932793
Py_DECREF(bytes);
27942794
return NULL;

Objects/complexobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,14 @@ try_complex_special_method(PyObject *op)
499499
}
500500
if (!PyComplex_Check(res)) {
501501
PyErr_Format(PyExc_TypeError,
502-
"%T.__complex__() must return type complex (not %T)",
502+
"%T.__complex__() must return a complex, not %T",
503503
op, res);
504504
Py_DECREF(res);
505505
return NULL;
506506
}
507507
/* Issue #29894: warn if 'res' not of exact type complex. */
508508
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
509-
"%T.__complex__() must return type complex (not %T). "
509+
"%T.__complex__() must return a complex, not %T. "
510510
"The ability to return an instance of a strict subclass of complex "
511511
"is deprecated, and may be removed in a future version of Python.",
512512
op, res)) {

Objects/fileobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ PyFile_GetLine(PyObject *f, int n)
6969
if (result != NULL && !PyBytes_Check(result) &&
7070
!PyUnicode_Check(result)) {
7171
PyErr_Format(PyExc_TypeError,
72-
"%T.readline() must return type str (not %T)", f, result);
72+
"%T.readline() must return a str, not %T", f, result);
7373
Py_SETREF(result, NULL);
7474
}
7575

@@ -194,7 +194,7 @@ PyObject_AsFileDescriptor(PyObject *o)
194194
}
195195
else {
196196
PyErr_Format(PyExc_TypeError,
197-
"%T.fileno() must return type int (not %T)", o, fno);
197+
"%T.fileno() must return an int, not %T", o, fno);
198198
Py_DECREF(fno);
199199
return -1;
200200
}

Objects/floatobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ PyFloat_AsDouble(PyObject *op)
288288
if (!PyFloat_CheckExact(res)) {
289289
if (!PyFloat_Check(res)) {
290290
PyErr_Format(PyExc_TypeError,
291-
"%T.__float__() must return type float (not %T)",
291+
"%T.__float__() must return a float, not %T",
292292
op, res);
293293
Py_DECREF(res);
294294
return -1;
295295
}
296296
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
297-
"%T.__float__() must return type float (not %T). "
297+
"%T.__float__() must return a float, not %T. "
298298
"The ability to return an instance of a strict subclass of float "
299299
"is deprecated, and may be removed in a future version of Python.",
300300
op, res)) {

Objects/funcobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ func_get_annotation_dict(PyFunctionObject *op)
558558
}
559559
if (!PyDict_Check(ann_dict)) {
560560
PyErr_Format(PyExc_TypeError,
561-
"__annotate__() must return type dict of type '%T'",
561+
"__annotate__() must return a dict, not %T",
562562
ann_dict);
563563
Py_DECREF(ann_dict);
564564
return NULL;

Objects/genobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,13 @@ _PyCoro_GetAwaitableIter(PyObject *o)
10831083
/* __await__ must return an *iterator*, not
10841084
a coroutine or another awaitable (see PEP 492) */
10851085
PyErr_Format(PyExc_TypeError,
1086-
"%T.__await__() must return type iterator (not coroutine)", o);
1086+
"%T.__await__() must return an iterator, "
1087+
"not coroutine", o);
10871088
Py_CLEAR(res);
10881089
} else if (!PyIter_Check(res)) {
10891090
PyErr_Format(PyExc_TypeError,
1090-
"%T.__await__() must return type iterator "
1091-
"of type '%T'", o, res);
1091+
"%T.__await__() must return an iterator, "
1092+
"not %T", o, res);
10921093
Py_CLEAR(res);
10931094
}
10941095
}

Objects/iterobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ anextawaitable_getiter(anextawaitableobject *obj)
358358
Py_SETREF(awaitable, new_awaitable);
359359
if (!PyIter_Check(awaitable)) {
360360
PyErr_Format(PyExc_TypeError,
361-
"%T.__await__() must return type iterable (not %T)",
361+
"%T.__await__() must return an iterable, not %T",
362362
obj, awaitable);
363363
Py_DECREF(awaitable);
364364
return NULL;

0 commit comments

Comments
 (0)