From 65e1b372b698636716518143a6827253f0c2c644 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 20 Oct 2012 19:12:41 +0200 Subject: [PATCH] made the module with cursor parser lazy --- jedi/modules.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/jedi/modules.py b/jedi/modules.py index 887248b4..69064680 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -54,16 +54,22 @@ class ModuleWithCursor(Module): self.source = source - try: - del builtin.CachedModule.cache[self.path] - except KeyError: - pass - # Call the parser already here, because it will be used anyways. - # Also, the position is here important (which will not be used by - # default), therefore fill the cache here. - self._parser = parsing.PyFuzzyParser(source, path, position) - if self.path: - builtin.CachedModule.cache[self.path] = time.time(), self._parser + @property + def parser(self): + """ get the parser lazy """ + if not self._parser: + try: + del builtin.CachedModule.cache[self.path] + except KeyError: + pass + # Call the parser already here, because it will be used anyways. + # Also, the position is here important (which will not be used by + # default), therefore fill the cache here. + self._parser = parsing.PyFuzzyParser(self.source, self.path, + self.position) + if self.path: + builtin.CachedModule.cache[self.path] = time.time(), self._parser + return self._parser def get_path_until_cursor(self): """ Get the path under the cursor. """