Bug in email package?

Roman Suzi rnd at onego.ru
Mon Feb 21 15:56:50 EST 2005


On Sun, 20 Feb 2005, Steven Bethard wrote:

> Erik Max Francis wrote:
>> Roman Suzi wrote:
>> 
>>> I think that if any object (from standard library at least) doesn't support
>>> iteration, it should clearly state so.
>>> 
>>> My guess is that 'for' causes the use of 'm[0]', which is (rightfully) an 
>>> error...
>>> 
>>> Can this behaviour of email be considered a bug?
>>> Is there a good case to iterate over something useful in a message
>> 
>> Why would it be a bug if the documentation never stated that the object was 
>> iterable?
>
> I think the bug is not that an error is produced, but that the _wrong_ error 
> is produced.  Trying to iterate over something that is not iterable should

Well, that was what I meant.

> produce a TypeError saying so (not an Attribute error):
>
> py> class C(object):
> ... 	pass
> ...
> py> iter(C())
> Traceback (most recent call last):
>  File "<interactive input>", line 1, in ?
> TypeError: iteration over non-sequence
>
> I've actually seen something like this come up before (I think with 
> email.Message even...)  I say call it a bug and submit a patch.

Ok. A bug minute on the next bug day ;-)

> It's pretty 
> easy to fix -- just add an __iter__ method to Message that raises a TypeError. 
> That makes it clear that Message doesn't intend to support the getitem 
> protocol -- it just does so accidentally because it provides __getitem__.
>
> STeVe
>

Sincerely yours, Roman Suzi
-- 
rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3



More information about the Python-list mailing list