[Python-Dev] zip -> izip; is length_hint required? (original) (raw)
Guido van Rossum guido at python.org
Fri Aug 25 01:08:26 CEST 2006
- Previous message: [Python-Dev] Need help with test_mutants.py
- Next message: [Python-Dev] zip -> izip; is __length_hint__ required?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/)
- Previous message: [Python-Dev] Need help with test_mutants.py
- Next message: [Python-Dev] zip -> izip; is __length_hint__ required?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]