Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

Please don't check the basic_consume callback for iscoroutinefunction #55

Closed smurfix closed 8 years ago

smurfix commented 8 years ago
aioamqp.exceptions.ConfigurationError: basic_consume requires a coroutine callback

This is a spurious error. One might want to use tools like functools.partial, or a nested function, to create the callback. Example:

yield from my_channel.basic_consume(my_queue, callback=functools.partial(self._on_rpc, my_data))

Checking for None (or maybe callable()) should be sufficient.

dzen commented 8 years ago

This problem is hard to solve, since a coroutine is also a callable :(

smurfix commented 8 years ago

With Python 3.4 it's possible to set function._is_coroutine=True to circumvent the test, but that's undocumented and not particularly future-proof …

dzen commented 8 years ago

Okay. the developper will have a nice error if he does not provide a coroutine :P

dzen commented 8 years ago

@smurfix any though ? Sorry for the API compatibility but removing the check without modifying the method signature didn't have any sense (to me).

smurfix commented 8 years ago

pika uses the same style (i.e. self, callback queue="", …) so this is OK with me.

It's not incompatible if the caller habitually uses keyword-only calling conventions. ;-)