Message13981
Logged In: YES
user_id=89016
The point is that Python/bltinmodule.c/builtin_reduce()
masks the error returned from PyObject_GetIter(). Errors
from PyIter_Next() are not masked.
What about the following example:
class LazyFile:
def __init__(self, name, mode="r"):
self.name = name
self.mode = mode
def __iter__(self):
return open(self.name, self.mode)
import operator
f = LazyFile("does not exist")
s = reduce(operator.add, f)
LazyFile *does* support iteration, but the underlying
problem of the non existing file is masked. Removing the
call PyErr_SetString(PyExc_TypeError, "reduce() arg 2 must
support iteration"); in builtin_reduce(), will produce the
original exception "IOError: [Errno 2] No such file or
directory: 'does not exist'" and when the second argument is
not iteratable, the original exception is just as good:
>>> reduce(lambda x,y: x+y, 42)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iteration over non-sequence
|
|
Date |
User |
Action |
Args |
2007-08-23 14:09:56 | admin | link | issue665761 messages |
2007-08-23 14:09:56 | admin | create | |
|