forked from VimPlug/jedi
Add memoize_function to cache and use it in fake.get_faked
The previously added test should now pass. Fix #591
This commit is contained in:
@@ -163,6 +163,18 @@ def memoize_method(method):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def memoize_function(obj):
|
||||||
|
""" A normal memoize function for memoizing free functions. """
|
||||||
|
cache = obj.cache = {}
|
||||||
|
|
||||||
|
def memoizer(*args, **kwargs):
|
||||||
|
key = str(args) + str(kwargs)
|
||||||
|
if key not in cache:
|
||||||
|
cache[key] = obj(*args, **kwargs)
|
||||||
|
return cache[key]
|
||||||
|
return memoizer
|
||||||
|
|
||||||
|
|
||||||
def cache_star_import(func):
|
def cache_star_import(func):
|
||||||
@time_cache("star_import_cache_validity")
|
@time_cache("star_import_cache_validity")
|
||||||
def wrapper(self):
|
def wrapper(self):
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import os
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from jedi._compatibility import is_py3, builtins, unicode
|
from jedi._compatibility import is_py3, builtins, unicode
|
||||||
|
from jedi.cache import memoize_function
|
||||||
from jedi.parser import Parser, load_grammar
|
from jedi.parser import Parser, load_grammar
|
||||||
from jedi.parser import tree as pt
|
from jedi.parser import tree as pt
|
||||||
from jedi.evaluate.helpers import FakeName
|
from jedi.evaluate.helpers import FakeName
|
||||||
@@ -97,6 +98,7 @@ def _faked(module, obj, name):
|
|||||||
return search_scope(cls, name)
|
return search_scope(cls, name)
|
||||||
|
|
||||||
|
|
||||||
|
@memoize_function
|
||||||
def get_faked(module, obj, name=None):
|
def get_faked(module, obj, name=None):
|
||||||
obj = obj.__class__ if is_class_instance(obj) else obj
|
obj = obj.__class__ if is_class_instance(obj) else obj
|
||||||
result = _faked(module, obj, name)
|
result = _faked(module, obj, name)
|
||||||
|
|||||||
Reference in New Issue
Block a user