mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-29730: replace some calls to PyNumber_Check and improve some error messages (#650)
This commit is contained in:
parent
b7c9150b68
commit
004251059b
5 changed files with 39 additions and 25 deletions
|
@ -578,12 +578,18 @@ _io_BytesIO_truncate_impl(bytesio *self, PyObject *arg)
|
|||
/* Truncate to current position if no argument is passed. */
|
||||
size = self->pos;
|
||||
}
|
||||
else {
|
||||
else if (PyIndex_Check(arg)) {
|
||||
size = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"argument should be integer or None, not '%.200s'",
|
||||
Py_TYPE(arg)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue