[Python-bugs-list] [ python-Bugs-665761 ] reduce() masks exception
SourceForge.net
noreply@sourceforge.net
Sat, 11 Jan 2003 09:08:22 -0800
Bugs item #665761, was opened at 2003-01-10 09:41
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=665761&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Nobody/Anonymous (nobody)
Summary: reduce() masks exception
Initial Comment:
In the following test script
-----
class Test:
def __iter__(self):
raise IOError
reduce(lambda x,y: x+y, Test())
-----
the real IOError exception is masked, i.e. the traceback is
-----
Traceback (most recent call last):
File "test.py", line 5, in ?
reduce(lambda x,y: x+y, Test())
TypeError: reduce() arg 2 must support iteration
-----
but IMHO should be
-----
Traceback (most recent call last):
File "test.py", line 3, in ?
raise IOError
IOError
-----
This can be fixed by removing the
PyErr_SetString(PyExc_TypeError, "reduce() arg 2 must
support iteration") call in
bltinmodule.c/buildtin_reduce().
----------------------------------------------------------------------
Comment By: Jp Calderone (kuran)
Date: 2003-01-11 12:08
Message:
Logged In: YES
user_id=366566
the __iter__ method is supposed to return an object that
defines a 'next' method. The returned object is the one
used for iteration, not the original. So I believe the
error message is correct - Test does not support iteration.
If you change the code to:
>>> class test:
... def __iter__(self):
... return self
... def next(self):
... raise IOError
...
>>> reduce(operator.add, test())
You get the expected result...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in next
IOError
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=665761&group_id=5470