mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-17 22:09:37 +08:00
underscore_memoization is now even easier in fast parser
This commit is contained in:
@@ -131,19 +131,6 @@ def underscore_memoization(func):
|
|||||||
return wrapper
|
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 cache_star_import(func):
|
||||||
def wrapper(evaluator, scope, *args, **kwargs):
|
def wrapper(evaluator, scope, *args, **kwargs):
|
||||||
with common.ignored(KeyError):
|
with common.ignored(KeyError):
|
||||||
|
|||||||
+10
-6
@@ -7,6 +7,7 @@ import re
|
|||||||
|
|
||||||
from jedi._compatibility import use_metaclass
|
from jedi._compatibility import use_metaclass
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
|
from jedi import common
|
||||||
from jedi.parser import Parser
|
from jedi.parser import Parser
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi.parser import tokenize
|
from jedi.parser import tokenize
|
||||||
@@ -28,7 +29,8 @@ class Module(pr.Simple, pr.Module):
|
|||||||
def reset_caches(self):
|
def reset_caches(self):
|
||||||
""" This module does a whole lot of caching, because it uses different
|
""" This module does a whole lot of caching, because it uses different
|
||||||
parsers. """
|
parsers. """
|
||||||
self._used_names = None
|
with common.ignored(AttributeError):
|
||||||
|
del self._used_names
|
||||||
for p in self.parsers:
|
for p in self.parsers:
|
||||||
p.user_scope = None
|
p.user_scope = None
|
||||||
p.user_stmt = None
|
p.user_stmt = None
|
||||||
@@ -40,7 +42,7 @@ class Module(pr.Simple, pr.Module):
|
|||||||
return getattr(self.parsers[0].module, name)
|
return getattr(self.parsers[0].module, name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@cache.underscore_none_memoization
|
@cache.underscore_memoization
|
||||||
def used_names(self):
|
def used_names(self):
|
||||||
used_names = {}
|
used_names = {}
|
||||||
for p in self.parsers:
|
for p in self.parsers:
|
||||||
@@ -198,7 +200,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@cache.underscore_none_memoization
|
@cache.underscore_memoization
|
||||||
def user_scope(self):
|
def user_scope(self):
|
||||||
user_scope = None
|
user_scope = None
|
||||||
for p in self.parsers:
|
for p in self.parsers:
|
||||||
@@ -212,7 +214,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
return user_scope
|
return user_scope
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@cache.underscore_none_memoization
|
@cache.underscore_memoization
|
||||||
def user_stmt(self):
|
def user_stmt(self):
|
||||||
user_stmt = None
|
user_stmt = None
|
||||||
for p in self.parsers:
|
for p in self.parsers:
|
||||||
@@ -431,8 +433,10 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
return p, node
|
return p, node
|
||||||
|
|
||||||
def reset_caches(self):
|
def reset_caches(self):
|
||||||
self._user_scope = None
|
with common.ignored(AttributeError):
|
||||||
self._user_stmt = None
|
del self._user_scope
|
||||||
|
with common.ignored(AttributeError):
|
||||||
|
del self._user_stmt
|
||||||
self.module.reset_caches()
|
self.module.reset_caches()
|
||||||
if self.current_node is not None:
|
if self.current_node is not None:
|
||||||
self.current_node.reset_contents()
|
self.current_node.reset_contents()
|
||||||
|
|||||||
Reference in New Issue
Block a user