Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add type information to error messages for ``__len__()`` and ``__sizeof__()``.
Patch by tangyuan0821.
4 changes: 2 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10625,8 +10625,8 @@ slot_sq_length(PyObject *self)
assert(PyLong_Check(res));
if (_PyLong_IsNegative((PyLongObject *)res)) {
Py_DECREF(res);
PyErr_SetString(PyExc_ValueError,
"__len__() should return >= 0");
PyErr_Format(PyExc_ValueError,
"%T.__len__() must return >= 0", self);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1933,8 +1933,8 @@ _PySys_GetSizeOf(PyObject *o)
return (size_t)-1;

if (size < 0) {
_PyErr_SetString(tstate, PyExc_ValueError,
"__sizeof__() should return >= 0");
_PyErr_Format(tstate, PyExc_ValueError,
"%T.__sizeof__() must return >= 0", o);
return (size_t)-1;
}

Expand Down
Loading