python: unpythonic result of Message.get_replies()

Subject: python: unpythonic result of Message.get_replies()

Date: Wed, 05 Oct 2011 03:42:38 +0200



From: Justus Winter

Hi everyone :)

I noticed that Message.get_replies() returns a Messages object *or*
None. Quoting the documentation:

> Returns: Messages or None if there are no replies to this message

Messages is a class implementing the iterator protocol, so a python
programmer would expect to get an iterator that raises a StopIteration
on the first invocation of next() if there aren't any replies.

With the current implementation one needs to do something like

replies = message.get_replies()
if replies != None:
    for reply in replies:

which looks awkward. Imho one should be able to just do

for reply in message.get_replies():

What do you think? Would it be possible to get this into the 0.9
release? I could propose a patch if you like, but not today...

.signature (application/octet-stream)