Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

The Queue class in the python kombu library inherits from MaybeChannelBound, which in turn implements the call method (making it callable). The call() method itself is a thin wrapper around the bind() method.

It is not clear why this was done, as calling the bind() method seems (to my simple mind, at least) to be clearer and more descriptive of the intent of the function.

Why would somebody use the call() method in a situation like this?

share|improve this question
To fulfill an Interface contract, perhaps? –  Robert Harvey May 29 '12 at 23:13
The offending check-in doesn't have any reasoning so I'll assume for brevity. link –  Avilo May 30 '12 at 6:56
There's not enough information for this question to be answerable. Any attempt to do so would most certainly involve examining the source code, which you haven't provided. –  Robert Harvey May 30 '12 at 18:53
@RobertHarvey - Please accept my apologies. The MaybeChannelBound object is defined here:, whilst it's subclass, Queue, is defined here: I am asking the question to gain some reassurance that I am not totally missing some fundamental idiom or design pattern. :-) –  William Payne May 30 '12 at 19:46

1 Answer 1

up vote 2 down vote accepted


I wrote the code, so I guess I should give an answer ;)

MaybeChannelBound is a common base class for Exchange and Queue, because they both have the same semantics (terrible name, as so often happens when one tries to use inheritance...)

The __call__ was an API decision, so:


returns a queue that is bound to a channel so that you can do operations on it. I simply thought the call looked better in the API, I don't remember exactly why I included the .bind method too, but I can guess that

  • If someone wanted to create a subclass of this, then overriding a bind operation would seem neater than using __call__.

  • When duck-typing it would be rather useless to check for __call__ (callable), and .bind could be used for this purpose.

In recent Kombu you rarely have to bind the channels yourself, e.g. when publishing a message you now send a list of entities to declare to Producer.publish instead (and declarations are cached too):

producer = Producer(connection)
producer.publish(message, retry=True, declare=[queue])

where you previously would have to write:

with as channel:

There isn't always any universally good reason for everything I do though, sometimes I do things just because it is a practice of mine. Sometimes those practices turns out the useful, other times they just end up being useless boilerplate.

share|improve this answer
Mystery solved. Thank you very much indeed. –  William Payne Jun 26 '12 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.