A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-June/015507.html below:

[Python-Dev] why not "return StopIteration"?

[Python-Dev] why not "return StopIteration"? [Python-Dev] why not "return StopIteration"?Neil Schemenauer nas@python.ca
Fri, 22 Jun 2001 07:43:17 -0700
Is "raise StopIteration" an abuse of exceptions?  Why can we not
use "return StopIteration" to signal the end of an iterator?
I've done a bit of hacking and the idea seems to work.

On possible problem is that the StopIteration object in the
builtin module could cause some confusing behavior.  For example
the code:

    for obj in __builtin__.__dict__.values():
        print obj

would not work as expected.  This could be fixed in most causes
by changing the tp_iternext protocol.  Something like:

    int tp_iternext(PyObject *it, PyObject **item)

were the return value is 1, 0, or -1.  IOW, StopIteration would not
have to come into the protocol if the object implemented
tp_iternext.

  Neil



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4