From 059b1e135397115a98f62432268d9fd29709508a Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 15 Jan 2014 15:57:43 +0100 Subject: [PATCH] underscore_memoization is now even easier in fast parser --- jedi/cache.py | 13 ------------- jedi/parser/fast.py | 16 ++++++++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/jedi/cache.py b/jedi/cache.py index 8ab3656b..6afb5f2f 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -131,19 +131,6 @@ def underscore_memoization(func): return wrapper -def underscore_none_memoization(func): - """Like ``underscore_memoization`` just with None instead of exceptions.""" - def wrapper(self): - name = '_' + func.__name__ - value = getattr(self, name) - if value is None: - value = func(self) - setattr(self, name, value) - return value - - return wrapper - - def cache_star_import(func): def wrapper(evaluator, scope, *args, **kwargs): with common.ignored(KeyError): diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index bd05b55d..cdd73df8 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -7,6 +7,7 @@ import re from jedi._compatibility import use_metaclass from jedi import settings +from jedi import common from jedi.parser import Parser from jedi.parser import representation as pr from jedi.parser import tokenize @@ -28,7 +29,8 @@ class Module(pr.Simple, pr.Module): def reset_caches(self): """ This module does a whole lot of caching, because it uses different parsers. """ - self._used_names = None + with common.ignored(AttributeError): + del self._used_names for p in self.parsers: p.user_scope = None p.user_stmt = None @@ -40,7 +42,7 @@ class Module(pr.Simple, pr.Module): return getattr(self.parsers[0].module, name) @property - @cache.underscore_none_memoization + @cache.underscore_memoization def used_names(self): used_names = {} for p in self.parsers: @@ -198,7 +200,7 @@ class FastParser(use_metaclass(CachedFastParser)): raise @property - @cache.underscore_none_memoization + @cache.underscore_memoization def user_scope(self): user_scope = None for p in self.parsers: @@ -212,7 +214,7 @@ class FastParser(use_metaclass(CachedFastParser)): return user_scope @property - @cache.underscore_none_memoization + @cache.underscore_memoization def user_stmt(self): user_stmt = None for p in self.parsers: @@ -431,8 +433,10 @@ class FastParser(use_metaclass(CachedFastParser)): return p, node def reset_caches(self): - self._user_scope = None - self._user_stmt = None + with common.ignored(AttributeError): + del self._user_scope + with common.ignored(AttributeError): + del self._user_stmt self.module.reset_caches() if self.current_node is not None: self.current_node.reset_contents()