Issue #25210: Change error message of do_richcompare()

Don't add parenthesis to type names. Add also quotes around the type names.

Before:

  TypeError: unorderable types: int() < NoneType()

After:

  TypeError: '<' not supported between instances of 'int' and 'NoneType'
This commit is contained in:
Victor Stinner 2015-10-14 18:25:31 +02:00
parent dbb98c1443
commit 91108f049f
4 changed files with 6 additions and 6 deletions

View File

@ -547,7 +547,8 @@ And this is what it gives:
Traceback (most recent call last): Traceback (most recent call last):
File "prog.py", line 11, in <module> File "prog.py", line 11, in <module>
if args.verbosity >= 2: if args.verbosity >= 2:
TypeError: unorderable types: NoneType() >= int() TypeError: '>=' not supported between instances of 'NoneType' and 'int'
* First output went well, and fixes the bug we had before. * First output went well, and fixes the bug we had before.
That is, we want any value >= 2 to be as verbose as possible. That is, we want any value >= 2 to be as verbose as possible.

View File

@ -257,7 +257,7 @@ members are not integers (but see `IntEnum`_ below)::
>>> Color.red < Color.blue >>> Color.red < Color.blue
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <module>
TypeError: unorderable types: Color() < Color() TypeError: '<' not supported between instances of 'Color' and 'Color'
Equality comparisons are defined though:: Equality comparisons are defined though::

View File

@ -195,7 +195,7 @@ Paths of a different flavour compare unequal and cannot be ordered::
>>> PureWindowsPath('foo') < PurePosixPath('foo') >>> PureWindowsPath('foo') < PurePosixPath('foo')
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <module>
TypeError: unorderable types: PureWindowsPath() < PurePosixPath() TypeError: '<' not supported between instances of 'PureWindowsPath' and 'PurePosixPath'
Operators Operators

View File

@ -686,11 +686,10 @@ do_richcompare(PyObject *v, PyObject *w, int op)
res = (v != w) ? Py_True : Py_False; res = (v != w) ? Py_True : Py_False;
break; break;
default: default:
/* XXX Special-case None so it doesn't show as NoneType() */
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"unorderable types: %.100s() %s %.100s()", "'%s' not supported between instances of '%.100s' and '%.100s'",
v->ob_type->tp_name,
opstrings[op], opstrings[op],
v->ob_type->tp_name,
w->ob_type->tp_name); w->ob_type->tp_name);
return NULL; return NULL;
} }