diff options
author | Florian Bruhin <me@the-compiler.org> | 2015-07-25 16:54:45 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2015-07-25 16:54:45 +0200 |
commit | 4dfc2332a6b858133a26343fb75e961ad302cb86 (patch) | |
tree | dd61e68cfed0cbe6ce05153018d25bca2cb24610 | |
parent | ec46421175b9b871621c960da8792ad8d3d6bd31 (diff) | |
download | astroid-4dfc2332a6b858133a26343fb75e961ad302cb86.tar.gz |
Simplify decorators.cache.
-rw-r--r-- | astroid/decorators.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/astroid/decorators.py b/astroid/decorators.py index 2992b8e..d98d993 100644 --- a/astroid/decorators.py +++ b/astroid/decorators.py @@ -28,13 +28,14 @@ def cached(func): @functools.wraps(func) def wrapped(wrapped_self): - if not getattr(wrapped_self, '__cache', None): - wrapped_self.__cache = {} - if func in wrapped_self.__cache: - return wrapped_self.__cache[func] - else: + cache = getattr(wrapped_self, '__cache', None) + if cache is None: + wrapped_self.__cache = cache = {} + try: + return cache[func] + except KeyError: result = func(wrapped_self) - wrapped_self.__cache[func] = result + cache[func] = result return result return wrapped |