[Python-Dev] zip -> izip; is __length_hint__ required?

Raymond Hettinger RHettinger at ewtllc.com
Sun Aug 27 17:26:10 CEST 2006


Yes, please rip that out.  The patch should be a direct copy of the code in the itertools module.  The use of length-hint was deliberately left-out of izip().
 
Also, yes it would be fine to alter the code in abstract.c to LBYL instead of suppressing exceptions.
 
 
Raymond

________________________________

From: gvanrossum at gmail.com on behalf of Guido van Rossum
Sent: Thu 8/24/2006 4:08 PM
To: Raymond Hettinger; python-dev at python.org; Brian Holmes
Subject: zip -> izip; is __length_hint__ required?



At today's sprint, Brian Holmes contributed a patch that implements
zip as an interator, a la izip. When reviewing Brian's code, I noticed
that he added an implementation of __length_hint__. My gut feeling is
that this isn't particularly useful given that zip() is almost
exclusively used iteratively, and rarely if ever converted to a list
or a tuple. (The one common exception is in the test suite, but there
it's almost always a short list, and 3 out of 5 were actually tests
for zip or izip.)

Should we rip it out or keep it?

Also, the existing convention for calling __length_hint__ (e.g. in
_PyObject_LengthHint() in abstract.c) seems to be to use
PyObject_CallMethod() and suppress TypeError and AttributeError coming
out of the call. It would seem to make much more sense to check
whether the attribute exists without calling it, and once it exists,
just call it and not suppress any exceptions that come out of it. Is
there any reason why this shouldn't work?

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060827/1360bfc8/attachment.htm 


More information about the Python-Dev mailing list