Bug in email package?

Steven Bethard steven.bethard at gmail.com
Sun Feb 20 20:21:47 EST 2005


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 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.  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



More information about the Python-list mailing list