bug in Message.__len__?

Asked by dbs

In message.py (bzr rev 70):

  def __len__(self):
    l = len(self.fields)
    if self.method.content:
      l += 1
    return len(self.fields)

Why is "l" computed but not returned?
Is there a side-effect I'm not seeing?

thanks,
<dbs>

Question information

Language:
English Edit question
Status:
Solved
For:
txAMQP Edit question
Assignee:
No assignee Edit question
Solved by:
dbs
Solved:
Last query:
Last reply:
Revision history for this message
Esteve Fernandez (esteve) said :
#1

True, I haven't seen a case where this breaks anything, but it should return l, not len(self.fields)

Thanks!

Revision history for this message
dbs (dbseraf) said :
#2

Is self.content the same as self.method.content? Because __len__ uses one
and __getitem__ uses the other. If they're different, I don't understand what
the function is intended to do.

Revision history for this message
Esteve Fernandez (esteve) said :
#3

self.content refers to a high-level Content/Body message, whereas self.method.content is the low-level representation of a Content message (i.e. the method payload)

Revision history for this message
dbs (dbseraf) said :
#4

That doesn't explain why __len__ uses one and __getitem__ uses the other, but I guess it must not matter.