[pypy-svn] r10034 - pypy/dist/pypy/module/builtin
hpk at codespeak.net
hpk at codespeak.net
Mon Mar 21 23:43:25 CET 2005
Author: hpk
Date: Mon Mar 21 23:43:24 2005
New Revision: 10034
Modified:
pypy/dist/pypy/module/builtin/operation.py
Log:
make the builtin iter() more picky about __iter__() results
that don't actually have a next() method.
Modified: pypy/dist/pypy/module/builtin/operation.py
==============================================================================
--- pypy/dist/pypy/module/builtin/operation.py (original)
+++ pypy/dist/pypy/module/builtin/operation.py Mon Mar 21 23:43:24 2005
@@ -91,7 +91,18 @@
def iter(space, w_collection_or_callable, w_sentinel=NoneNotWrapped):
if w_sentinel is None:
- return space.iter(w_collection_or_callable)
+ w_res = space.iter(w_collection_or_callable)
+ w_typeres = space.type(w_res)
+ try:
+ space.getattr(w_typeres, space.wrap('next'))
+ except OperationError, e:
+ if not e.match(space, space.w_AttributeError):
+ raise
+ raise OperationError(space.w_TypeError,
+ space.wrap("iter() returned non-iterator of type '%s'" %
+ w_typeres.name))
+ else:
+ return w_res
else:
return iter_sentinel(space, w_collection_or_callable, w_sentinel)
More information about the Pypy-commit
mailing list