summaryrefslogtreecommitdiff
path: root/astroid/decorators.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-08-26 10:16:54 -0400
committerCeridwen <ceridwenv@gmail.com>2015-08-26 10:16:54 -0400
commit61e41bd688f84a206d7a3bc181eac65aae1b686d (patch)
treec1a3bbcb61b16c096cfb0d5df48200c29e125727 /astroid/decorators.py
parent6fbe7dfe39e4938dcae3c6bbafa05249f43715ad (diff)
downloadastroid-61e41bd688f84a206d7a3bc181eac65aae1b686d.tar.gz
Improve decorator introspection using wrapt and functools.wraps
Diffstat (limited to 'astroid/decorators.py')
-rw-r--r--astroid/decorators.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/astroid/decorators.py b/astroid/decorators.py
index 4bc7ff1..2c6e40b 100644
--- a/astroid/decorators.py
+++ b/astroid/decorators.py
@@ -21,24 +21,21 @@
""" A few useful function/method decorators."""
-import functools
+import wrapt
-def cached(func):
+@wrapt.decorator
+def cached(func, instance, args, kwargs):
"""Simple decorator to cache result of method calls without args."""
-
- @functools.wraps(func)
- def wrapped(wrapped_self):
- cache = getattr(wrapped_self, '__cache', None)
- if cache is None:
- wrapped_self.__cache = cache = {}
- try:
- return cache[func]
- except KeyError:
- cache[func] = result = func(wrapped_self)
- return result
-
- return wrapped
+ wrapped_self, = args
+ cache = getattr(wrapped_self, '__cache', None)
+ if cache is None:
+ wrapped_self.__cache = cache = {}
+ try:
+ return cache[func]
+ except KeyError:
+ cache[func] = result = func(wrapped_self)
+ return result
class cachedproperty(object):