mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
Change ValueErrors to TypeErrors and add PyList_Check() assertions.
This commit is contained in:
parent
236a2443fb
commit
6dab05231d
1 changed files with 6 additions and 4 deletions
|
@ -14,6 +14,7 @@ _siftdown(PyListObject *heap, int startpos, int pos)
|
||||||
PyObject *newitem, *parent;
|
PyObject *newitem, *parent;
|
||||||
int cmp, parentpos;
|
int cmp, parentpos;
|
||||||
|
|
||||||
|
assert(PyList_Check(heap));
|
||||||
if (pos >= PyList_GET_SIZE(heap)) {
|
if (pos >= PyList_GET_SIZE(heap)) {
|
||||||
PyErr_SetString(PyExc_IndexError, "index out of range");
|
PyErr_SetString(PyExc_IndexError, "index out of range");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -48,6 +49,7 @@ _siftup(PyListObject *heap, int pos)
|
||||||
int cmp;
|
int cmp;
|
||||||
PyObject *newitem, *tmp;
|
PyObject *newitem, *tmp;
|
||||||
|
|
||||||
|
assert(PyList_Check(heap));
|
||||||
endpos = PyList_GET_SIZE(heap);
|
endpos = PyList_GET_SIZE(heap);
|
||||||
startpos = pos;
|
startpos = pos;
|
||||||
if (pos >= endpos) {
|
if (pos >= endpos) {
|
||||||
|
@ -97,7 +99,7 @@ heappush(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!PyList_Check(heap)) {
|
if (!PyList_Check(heap)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "heap argument must be a list");
|
PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ heappop(PyObject *self, PyObject *heap)
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!PyList_Check(heap)) {
|
if (!PyList_Check(heap)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "heap argument must be a list");
|
PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +161,7 @@ heapreplace(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!PyList_Check(heap)) {
|
if (!PyList_Check(heap)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "heap argument must be a list");
|
PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +194,7 @@ heapify(PyObject *self, PyObject *heap)
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
if (!PyList_Check(heap)) {
|
if (!PyList_Check(heap)) {
|
||||||
PyErr_SetString(PyExc_ValueError, "heap argument must be a list");
|
PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue