cpython: b9dedf845a0f (original) (raw)
Mercurial > cpython
changeset 79561:b9dedf845a0f
Issue #16148: Small improvements and cleanup. Added version information to docs. [#16148]
Armin Ronacher armin.ronacher@active-4.com | |
---|---|
date | Sun, 07 Oct 2012 10:29:32 +0200 |
parents | bf5da9433000 |
children | c4e39d4584f2 |
files | Doc/c-api/object.rst Doc/library/operator.rst Doc/reference/datamodel.rst Include/abstract.h Lib/test/test_enumerate.py Objects/abstract.c |
diffstat | 6 files changed, 24 insertions(+), 9 deletions(-)[+] [-] Doc/c-api/object.rst 2 Doc/library/operator.rst 2 Doc/reference/datamodel.rst 9 Include/abstract.h 4 Lib/test/test_enumerate.py 1 Objects/abstract.c 15 |
line wrap: on
line diff
--- a/Doc/c-api/object.rst
+++ b/Doc/c-api/object.rst
@@ -349,6 +349,8 @@ is considered sufficient for this determ
returning the default value. On error -1
is returned. This is the
equivalent to the Python expression operator.length_hint(o, default)
.
.. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key) Return element of o corresponding to the object key or NULL on failure.
--- a/Doc/library/operator.rst
+++ b/Doc/library/operator.rst
@@ -241,6 +241,8 @@ their character equivalents.
actual length, then an estimate using __length_hint__
, and finally
returning the default value.
The :mod:operator
module also defines tools for generalized attribute and item
lookups. These are useful for making fast field extractors as arguments for
:func:map
, :func:sorted
, :meth:itertools.groupby
, or other functions that
--- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1805,6 +1805,15 @@ through the container; for mappings, :me considered to be false in a Boolean context. +.. method:: object.length_hint(self) +
- Called to implement
operator.length_hint
. Should return an estimated - length for the object (which may be greater or less than the actual length).
- The length must be an integer
>=
0. This method is purely an - optimization and is never required for correctness. +
- .. versionadded:: 3.4 +
.. note:: Slicing is done exclusively with the following three methods. A call like ::
--- a/Include/abstract.h +++ b/Include/abstract.h @@ -403,7 +403,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); #define PyObject_Length PyObject_Size -PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); +#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);[](#l4.9)
+#endif PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject o, Py_ssize_t); /
--- a/Lib/test/test_enumerate.py +++ b/Lib/test/test_enumerate.py @@ -170,7 +170,6 @@ class TestReversed(unittest.TestCase, Pi self.assertEqual(type(reversed(x)), type(iter(x))) def test_len(self):
# This is an implementation detail, not an interface requirement[](#l5.7) for s in ('hello', tuple('hello'), list('hello'), range(5)):[](#l5.8) self.assertEqual(operator.length_hint(reversed(s)), len(s))[](#l5.9) r = reversed(s)[](#l5.10)
--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -71,8 +71,9 @@ int } /* 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_ssiz return defaultvalue; } if (!PyLong_Check(result)) {
PyErr_Format(PyExc_TypeError, "Length hint must be an integer, not %s",[](#l6.19)