1
0
forked from VimPlug/jedi

Move underscore memoization.

This commit is contained in:
Dave Halter
2017-03-30 01:52:01 +02:00
parent 54d69fb9f4
commit db364bc44d
2 changed files with 35 additions and 36 deletions

View File

@@ -1,4 +1,3 @@
import inspect
import time
import os
import sys
@@ -45,40 +44,6 @@ parser_cache = {}
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)
if inspect.isgenerator(result):
result = list(result)
setattr(self, name, result)
return result
return wrapper
class _NodeCacheItem(object):
def __init__(self, node, lines, change_time=None):
self.node = node