mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Remove underscore_memoization caching method
This commit is contained in:
@@ -20,38 +20,6 @@ from parso.cache import parser_cache
|
|||||||
_time_caches = {}
|
_time_caches = {}
|
||||||
|
|
||||||
|
|
||||||
def underscore_memoization(func):
|
|
||||||
"""
|
|
||||||
Decorator for methods::
|
|
||||||
|
|
||||||
class A(object):
|
|
||||||
def x(self):
|
|
||||||
if self._x:
|
|
||||||
self._x = 10
|
|
||||||
return self._x
|
|
||||||
|
|
||||||
Becomes::
|
|
||||||
|
|
||||||
class A(object):
|
|
||||||
@underscore_memoization
|
|
||||||
def x(self):
|
|
||||||
return 10
|
|
||||||
|
|
||||||
A now has an attribute ``_x`` written by this decorator.
|
|
||||||
"""
|
|
||||||
name = '_' + func.__name__
|
|
||||||
|
|
||||||
def wrapper(self):
|
|
||||||
try:
|
|
||||||
return getattr(self, name)
|
|
||||||
except AttributeError:
|
|
||||||
result = func(self)
|
|
||||||
setattr(self, name, result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def clear_time_caches(delete_all=False):
|
def clear_time_caches(delete_all=False):
|
||||||
""" Jedi caches many things, that should be completed after each completion
|
""" Jedi caches many things, that should be completed after each completion
|
||||||
finishes.
|
finishes.
|
||||||
|
|||||||
@@ -10,15 +10,14 @@ from jedi.parser_utils import get_cached_code_lines
|
|||||||
|
|
||||||
from jedi._compatibility import unwrap
|
from jedi._compatibility import unwrap
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
|
from jedi.cache import memoize_method
|
||||||
from jedi.inference import compiled
|
from jedi.inference import compiled
|
||||||
from jedi.cache import underscore_memoization
|
|
||||||
from jedi.file_io import FileIO
|
from jedi.file_io import FileIO
|
||||||
from jedi.inference.base_value import ValueSet, ValueWrapper, NO_VALUES
|
from jedi.inference.base_value import ValueSet, ValueWrapper, NO_VALUES
|
||||||
from jedi.inference.value import ModuleValue
|
from jedi.inference.value import ModuleValue
|
||||||
from jedi.inference.cache import inference_state_function_cache, \
|
from jedi.inference.cache import inference_state_function_cache, \
|
||||||
inference_state_method_cache
|
inference_state_method_cache
|
||||||
from jedi.inference.compiled.access import compiled_objects_cache, \
|
from jedi.inference.compiled.access import ALLOWED_GETITEM_TYPES, get_api_type
|
||||||
ALLOWED_GETITEM_TYPES, get_api_type
|
|
||||||
from jedi.inference.compiled.value import create_cached_compiled_object, create_from_name
|
from jedi.inference.compiled.value import create_cached_compiled_object, create_from_name
|
||||||
from jedi.inference.gradual.conversion import to_stub
|
from jedi.inference.gradual.conversion import to_stub
|
||||||
from jedi.inference.context import CompiledContext, CompiledModuleContext, \
|
from jedi.inference.context import CompiledContext, CompiledModuleContext, \
|
||||||
@@ -115,7 +114,7 @@ class MixedName(compiled.CompiledName):
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
return values[0].name.start_pos
|
return values[0].name.start_pos
|
||||||
|
|
||||||
@underscore_memoization
|
@memoize_method
|
||||||
def infer(self):
|
def infer(self):
|
||||||
# TODO use logic from compiled.CompiledObjectFilter
|
# TODO use logic from compiled.CompiledObjectFilter
|
||||||
access_paths = self._parent_value.access_handle.getattr_paths(
|
access_paths = self._parent_value.access_handle.getattr_paths(
|
||||||
@@ -258,6 +257,7 @@ def _find_syntax_node_name(inference_state, python_object):
|
|||||||
return module_node, tree_node, file_io, code_lines
|
return module_node, tree_node, file_io, code_lines
|
||||||
|
|
||||||
|
|
||||||
|
@inference_state_function_cache()
|
||||||
def _create(inference_state, compiled_object, module_context):
|
def _create(inference_state, compiled_object, module_context):
|
||||||
# TODO accessing this is bad, but it probably doesn't matter that much,
|
# TODO accessing this is bad, but it probably doesn't matter that much,
|
||||||
# because we're working with interpreteters only here.
|
# because we're working with interpreteters only here.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from functools import partial
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.inference.utils import to_list
|
from jedi.inference.utils import to_list
|
||||||
from jedi._compatibility import force_unicode, Parameter, cast_path
|
from jedi._compatibility import force_unicode, Parameter, cast_path
|
||||||
from jedi.cache import underscore_memoization, memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.inference.filters import AbstractFilter
|
from jedi.inference.filters import AbstractFilter
|
||||||
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
from jedi.inference.names import AbstractNameDefinition, ValueNameMixin, \
|
||||||
ParamNameInterface
|
ParamNameInterface
|
||||||
@@ -139,7 +139,7 @@ class CompiledObject(Value):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self.access_handle.get_repr())
|
return '<%s: %s>' % (self.__class__.__name__, self.access_handle.get_repr())
|
||||||
|
|
||||||
@underscore_memoization
|
@memoize_method
|
||||||
def _parse_function_doc(self):
|
def _parse_function_doc(self):
|
||||||
doc = self.py__doc__()
|
doc = self.py__doc__()
|
||||||
if doc is None:
|
if doc is None:
|
||||||
@@ -151,15 +151,6 @@ class CompiledObject(Value):
|
|||||||
def api_type(self):
|
def api_type(self):
|
||||||
return self.access_handle.get_api_type()
|
return self.access_handle.get_api_type()
|
||||||
|
|
||||||
@underscore_memoization
|
|
||||||
def _cls(self):
|
|
||||||
"""
|
|
||||||
We used to limit the lookups for instantiated objects like list(), but
|
|
||||||
this is not the case anymore. Python itself
|
|
||||||
"""
|
|
||||||
# Ensures that a CompiledObject is returned that is not an instance (like list)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def get_filters(self, is_instance=False, origin_scope=None):
|
def get_filters(self, is_instance=False, origin_scope=None):
|
||||||
yield self._ensure_one_filter(is_instance)
|
yield self._ensure_one_filter(is_instance)
|
||||||
|
|
||||||
@@ -361,7 +352,7 @@ class CompiledName(AbstractNameDefinition):
|
|||||||
return "instance"
|
return "instance"
|
||||||
return next(iter(api)).api_type
|
return next(iter(api)).api_type
|
||||||
|
|
||||||
@underscore_memoization
|
@memoize_method
|
||||||
def infer(self):
|
def infer(self):
|
||||||
return ValueSet([create_from_name(
|
return ValueSet([create_from_name(
|
||||||
self._inference_state, self._parent_value, self.string_name
|
self._inference_state, self._parent_value, self.string_name
|
||||||
|
|||||||
Reference in New Issue
Block a user