From 6103ca92b555dcccd74f8f7eeb39186bef1f646b Mon Sep 17 00:00:00 2001 From: Carl Oscar Aaro Date: Sat, 5 Aug 2017 17:26:27 +0200 Subject: [PATCH] Fixes issue with AMQP transport and reverts old invalid commit --- examples/amqp_service.py | 1 - tomodachi/transport/amqp.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/amqp_service.py b/examples/amqp_service.py index d2a78748e..33ff5ae67 100644 --- a/examples/amqp_service.py +++ b/examples/amqp_service.py @@ -23,7 +23,6 @@ class ExampleAmqpService(object): @amqp('example.route1') async def route1a(self, data: Any) -> None: - banana = True self.logger.info('Received data (function: route1a) - "{}"'.format(data)) @amqp('example.route1') diff --git a/tomodachi/transport/amqp.py b/tomodachi/transport/amqp.py index 130e9d2a4..2042206ee 100644 --- a/tomodachi/transport/amqp.py +++ b/tomodachi/transport/amqp.py @@ -5,6 +5,7 @@ import re import binascii import asyncio +import inspect from typing import Any, Dict, Union, Optional, Callable, Awaitable, Match from tomodachi.invoker import Invoker @@ -102,7 +103,8 @@ async def subscribe_handler(cls: Any, obj: Any, context: Dict, func: Any, routin async def handler(payload: Any, delivery_tag: Any) -> Any: _callback_kwargs = callback_kwargs # type: Any if not _callback_kwargs: - _callback_kwargs = {k: func.__defaults__[len(func.__defaults__) - len(func.__code__.co_varnames[1:]) + i] if func.__defaults__ and len(func.__defaults__) - len(func.__code__.co_varnames[1:]) + i >= 0 else None for i, k in enumerate(func.__code__.co_varnames[1:])} + values = inspect.getfullargspec(func) + _callback_kwargs = {k: values.defaults[i - len(values.args) + 1] if values.defaults and i >= len(values.args) - len(values.defaults) - 1 else None for i, k in enumerate(values.args[1:])} if values.args and len(values.args) > 1 else {} else: _callback_kwargs = {k: None for k in _callback_kwargs if k != 'self'} kwargs = {k: v for k, v in _callback_kwargs.items()}