From 8bde54a07280031eb272b475ee2ae461deee0e2c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 25 Jan 2020 17:29:52 +0100 Subject: [PATCH] Remove underscore_memoization caching method --- jedi/cache.py | 32 -------------------------------- jedi/inference/compiled/mixed.py | 8 ++++---- jedi/inference/compiled/value.py | 15 +++------------ 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/jedi/cache.py b/jedi/cache.py index e2ba9374..29ed979f 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -20,38 +20,6 @@ from parso.cache import parser_cache _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): """ Jedi caches many things, that should be completed after each completion finishes. diff --git a/jedi/inference/compiled/mixed.py b/jedi/inference/compiled/mixed.py index 94a99a70..43b8d9f8 100644 --- a/jedi/inference/compiled/mixed.py +++ b/jedi/inference/compiled/mixed.py @@ -10,15 +10,14 @@ from jedi.parser_utils import get_cached_code_lines from jedi._compatibility import unwrap from jedi import settings +from jedi.cache import memoize_method from jedi.inference import compiled -from jedi.cache import underscore_memoization from jedi.file_io import FileIO from jedi.inference.base_value import ValueSet, ValueWrapper, NO_VALUES from jedi.inference.value import ModuleValue from jedi.inference.cache import inference_state_function_cache, \ inference_state_method_cache -from jedi.inference.compiled.access import compiled_objects_cache, \ - ALLOWED_GETITEM_TYPES, get_api_type +from jedi.inference.compiled.access import ALLOWED_GETITEM_TYPES, get_api_type from jedi.inference.compiled.value import create_cached_compiled_object, create_from_name from jedi.inference.gradual.conversion import to_stub from jedi.inference.context import CompiledContext, CompiledModuleContext, \ @@ -115,7 +114,7 @@ class MixedName(compiled.CompiledName): return 0, 0 return values[0].name.start_pos - @underscore_memoization + @memoize_method def infer(self): # TODO use logic from compiled.CompiledObjectFilter 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 +@inference_state_function_cache() def _create(inference_state, compiled_object, module_context): # TODO accessing this is bad, but it probably doesn't matter that much, # because we're working with interpreteters only here. diff --git a/jedi/inference/compiled/value.py b/jedi/inference/compiled/value.py index 11c6ca55..99cabd91 100644 --- a/jedi/inference/compiled/value.py +++ b/jedi/inference/compiled/value.py @@ -7,7 +7,7 @@ from functools import partial from jedi import debug from jedi.inference.utils import to_list 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.names import AbstractNameDefinition, ValueNameMixin, \ ParamNameInterface @@ -139,7 +139,7 @@ class CompiledObject(Value): def __repr__(self): return '<%s: %s>' % (self.__class__.__name__, self.access_handle.get_repr()) - @underscore_memoization + @memoize_method def _parse_function_doc(self): doc = self.py__doc__() if doc is None: @@ -151,15 +151,6 @@ class CompiledObject(Value): def api_type(self): 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): yield self._ensure_one_filter(is_instance) @@ -361,7 +352,7 @@ class CompiledName(AbstractNameDefinition): return "instance" return next(iter(api)).api_type - @underscore_memoization + @memoize_method def infer(self): return ValueSet([create_from_name( self._inference_state, self._parent_value, self.string_name