summaryrefslogtreecommitdiff
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-03-13 00:37:05 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2017-03-13 00:37:05 +0200
commit004251059b9c5e48d47cb30b94bcb92cb44d3adf (patch)
treec61cee2b14c069cf40ce39910980d338687f4bc7 /Modules/_io/bytesio.c
parentb7c9150b68516878175e5373983189d6deea470c (diff)
downloadcpython-git-004251059b9c5e48d47cb30b94bcb92cb44d3adf.tar.gz
bpo-29730: replace some calls to PyNumber_Check and improve some error messages (#650)
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 0a0e5e72d7..59b917d0bd 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -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,