diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2012-10-07 08:29:32 (GMT) |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2012-10-07 08:29:32 (GMT) |
commit | 74b38b190faae988b4951cf46d83f853589aa530 (patch) | |
tree | 3259a32fff2a205c6d3d74d9a04c165eb5908686 /Objects/abstract.c | |
parent | 96e936712f2d926fb566c8680958a07fc6b84c71 (diff) | |
download | cpython-74b38b190faae988b4951cf46d83f853589aa530.zip cpython-74b38b190faae988b4951cf46d83f853589aa530.tar.gz cpython-74b38b190faae988b4951cf46d83f853589aa530.tar.bz2 |
Issue #16148: Small improvements and cleanup. Added version information
to docs.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 84e827a..4326cfa 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -71,8 +71,9 @@ _PyObject_HasLen(PyObject *o) { } /* The length hint function returns a non-negative value from o.__len__() - or o.__length_hint__(). If those methods aren't found. If one of the calls - fails this function returns -1. + or o.__length_hint__(). If those methods aren't found the defaultvalue is + returned. If one of the calls fails with an exception other than TypeError + this function returns -1. */ Py_ssize_t @@ -112,21 +113,21 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return defaultvalue; } if (!PyLong_Check(result)) { - PyErr_Format(PyExc_TypeError, "Length hint must be an integer, not %s", + PyErr_Format(PyExc_TypeError, "__length_hint__ must be an integer, not %.100s", Py_TYPE(result)->tp_name); Py_DECREF(result); return -1; } - defaultvalue = PyLong_AsSsize_t(result); + res = PyLong_AsSsize_t(result); Py_DECREF(result); - if (defaultvalue < 0 && PyErr_Occurred()) { + if (res < 0 && PyErr_Occurred()) { return -1; } - if (defaultvalue < 0) { + if (res < 0) { PyErr_Format(PyExc_ValueError, "__length_hint__() should return >= 0"); return -1; } - return defaultvalue; + return res; } PyObject * |