[Python-projects] Assertions, type checking, and testing
Maarten ter Huurne
maarten.ter.huurne at philips.com
Mon Jun 26 15:53:17 CEST 2006
You wrote on 2006-06-22 09:27:16 PM:
> On Thu, 22 Jun 2006, Maarten ter Huurne wrote:
> [...]
> > strict. For example, an iteration always ends with the StopIteration
> > exception being raised.
> [...]
>
> I don't think that's quite true, is it? AFAIK, the interpreter is free
to
> implement iteration over instances of builtin types without raising
> StopIteration, for example.
It is possible indeed that the interpreter has special optimized paths for
commonly used types. But I cannot know for sure without diving into the
Python source code.
However, as soon as you deal with iterators explicitly, even on built-in
types, StopIteration is raised. For example "iter([]).next()" raises it.
Also, if you inherit from "list" and override "__iter__", that method is
called. So if those optimisations are present, they are invisible to the
user.
Bye,
Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20060626/dc0daf32/attachment.html
More information about the Python-Projects
mailing list