[Python-Dev] cpython: Issue #16148: implemented PEP 424 (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Sat Oct 6 14:37:02 CEST 2012


On Sat, 6 Oct 2012 14:12:36 +0200 (CEST) armin.ronacher <python-checkins at python.org> wrote:

http://hg.python.org/cpython/rev/a7ec0a1b0f7c changeset: 79511:a7ec0a1b0f7c parent: 79507:3c1df1ede882 user: Armin Ronacher <armin.ronacher at active-4.com> date: Sat Oct 06 14:03:24 2012 +0200 summary: Issue #16148: implemented PEP 424 [...]

+.. c:function:: Pyssizet PyObjectLengthHint(PyObject *o, Pyssizet default) + + Return an estimated length for the object o. First trying to return its + actual length, then an estimate using _lengthhint_, and finally + returning the default value. On error -1 is returned. This is the + equivalent to the Python expression operator.lengthhint(o, default). +

You need a "versionadded" marker.

+.. function:: lengthhint(obj, default=0) + + Return an estimated length for the object o. First trying to return its + actual length, then an estimate using _lengthhint_, and finally + returning the default value. +

Here as well.

-#ifndef PyLIMITEDAPI - PyAPIFUNC(Pyssizet) PyObjectLengthHint(PyObject *o, Pyssizet); -#endif +PyAPIFUNC(int) PyObjectHasLen(PyObject *o); +PyAPIFUNC(Pyssizet) PyObjectLengthHint(PyObject *o, Pyssizet);

If _PyObject_HasLen is private, it shouldn't be in the Py_LIMITED_API.

diff --git a/Lib/test/testenumerate.py b/Lib/test/testenumerate.py --- a/Lib/test/testenumerate.py +++ b/Lib/test/testenumerate.py @@ -1,4 +1,5 @@ import unittest +import operator import sys import pickle

@@ -168,15 +169,13 @@ x = range(1) self.assertEqual(type(reversed(x)), type(iter(x))) - @support.cpythononly def testlen(self): # This is an implementation detail, not an interface requirement - from test.testiterlen import len for s in ('hello', tuple('hello'), list('hello'), range(5)): - self.assertEqual(len(reversed(s)), len(s)) + self.assertEqual(operator.lengthhint(reversed(s)), len(s))

You should still test len() as well, no?

+ else { + return res; + } + PyObject *hint = PyObjectLookupSpecial(o, &PyId_lengthhint);_

Putting variable declarations in the middle of code blocks is not C89-compliant. You probably broke a couple of buildbots :-)

+ if (PyObjectHasLen(it->itseq)) { + seqsize = PySequenceSize(it->itseq); + if (seqsize == -1) + return NULL; + } + else { + return PyNotImplemented; + }

Lacks a Py_INCREF?

Regards

Antoine.

-- Software development and contracting: http://pro.pitrou.net



More information about the Python-Dev mailing list