[Python-3000] Builtin iterator type

Aaron Bingham bingham at cenix-bioscience.com
Mon Nov 20 10:46:16 CET 2006


Guido van Rossum wrote:

>On 11/18/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
>  
>
>>(Although I will point out
>>that most  protocols for things like len() *do* involve checks for special
>>methods by name, and the check for iterability is typically a non-destructive
>>call to iter(x), rather than a destructive one to x.next()).
>>    
>>
>
>Ouch?! I would never check for iterability explicitly. I would just
>require it, as Greg Ewing says. iter() could be fairly expensive,
>depending on what is being iterated over.
>
>Maybe this is unique to iterators and iterators are a bad example? I
>don't feel as strongly about this when testing e.g. for string-ness,
>file-ness or list-ness. While I tend to dislike those tests too, they
>are sometimes inevitable when we want to overload an API. Especially
>file/string is often overloaded, and I see no big problem with this (I
>do dislike overloading list/dict, or string/list-of-strings).
>
Might I point out that with Design by Contract, it is impossible to 
write a correct and complete precondition if nondestructive tests are 
not available.

Regards,

-- 
--------------------------------------------------------------------
Aaron Bingham
Senior Software Engineer
Cenix BioScience GmbH
--------------------------------------------------------------------



More information about the Python-3000 mailing list