diff --git a/aiocache/decorators.py b/aiocache/decorators.py index 81a5b25f..8d924faf 100644 --- a/aiocache/decorators.py +++ b/aiocache/decorators.py @@ -1,4 +1,5 @@ import inspect +import functools from aiocache.log import logger from aiocache import SimpleMemoryCache, caches @@ -39,6 +40,7 @@ def cached( cache_kwargs = kwargs def cached_decorator(func): + @functools.wraps(func) async def wrapper(*args, **kwargs): if alias: cache_instance = caches.create(alias) @@ -102,6 +104,7 @@ def multi_cached( cache_kwargs = kwargs def multi_cached_decorator(func): + @functools.wraps(func) async def wrapper(*args, **kwargs): if alias: cache_instance = caches.create(alias) diff --git a/tests/ut/test_decorators.py b/tests/ut/test_decorators.py index 93bb690f..3fcc5e81 100644 --- a/tests/ut/test_decorators.py +++ b/tests/ut/test_decorators.py @@ -1,6 +1,7 @@ import sys import pytest import random +import inspect import asynctest from unittest import mock @@ -197,6 +198,16 @@ async def test_cached_alias_takes_precedence(self, mocker, memory_mock_cache, mo assert memory_mock_cache.get.call_count == 0 assert memory_mock_cache.set.call_count == 0 + @pytest.mark.asyncio + async def test_cached_keeps_signature(self): + @cached() + async def what(self, a, b): + return "1" + + assert what.__name__ == "what" + assert str(inspect.signature(what)) == '(self, a, b)' + assert inspect.getfullargspec(what.__wrapped__).args == ['self', 'a', 'b'] + class TestMultiCachedDecorator: @@ -337,6 +348,16 @@ async def test_multi_cached_alias_takes_precedence(self, mocker, memory_mock_cac assert memory_mock_cache.multi_get.call_count == 0 assert memory_mock_cache.multi_set.call_count == 0 + @pytest.mark.asyncio + async def test_multi_cached_keeps_signature(self): + @multi_cached('keys') + async def what(self, keys, a, b): + return "1" + + assert what.__name__ == "what" + assert str(inspect.signature(what)) == '(self, keys, a, b)' + assert inspect.getfullargspec(what.__wrapped__).args == ['self', 'keys', 'a', 'b'] + def test_get_args_dict():