mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
builtin cache reloads modules if they changed
This commit is contained in:
15
builtin.py
15
builtin.py
@@ -13,6 +13,8 @@ class Parser(object):
|
||||
It can be instantiated with either a path or a name of the module. The path
|
||||
is important for third party modules.
|
||||
|
||||
TODO maybe remove some code and merge it with `modules`?
|
||||
|
||||
:param name: The name of the module.
|
||||
:param path: The path of the module.
|
||||
:param sys_path: The sys.path, which is can be customizable.
|
||||
@@ -67,7 +69,12 @@ class Parser(object):
|
||||
""" get the parser lazy """
|
||||
if not self._parser:
|
||||
try:
|
||||
self._parser = Parser.cache[self.name, self.path].parser
|
||||
timestamp, parser = Parser.cache[self.name, self.path]
|
||||
if timestamp == os.path.getmtime(self.path):
|
||||
debug.dbg('hit builtin cache')
|
||||
self._parser = parser
|
||||
else:
|
||||
raise KeyError
|
||||
except KeyError:
|
||||
code = self._generate_code(self.module)
|
||||
try:
|
||||
@@ -77,7 +84,11 @@ class Parser(object):
|
||||
#open('builtin_fail', 'w').write(code)
|
||||
raise
|
||||
else:
|
||||
Parser.cache[self.name, self.path] = self
|
||||
if self.path:
|
||||
p_time = os.path.getmtime(self.path)
|
||||
else:
|
||||
p_time = None
|
||||
Parser.cache[self.name, self.path] = p_time, self._parser
|
||||
return self._parser
|
||||
|
||||
def _generate_code(self, scope, depth=0):
|
||||
|
||||
4
ftest.py
4
ftest.py
@@ -16,5 +16,7 @@ code = f.read()
|
||||
for i in range(1):
|
||||
completions = functions.complete(code, 150, 200, path)
|
||||
|
||||
#print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||
print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||
#print [n.name for n in completions]
|
||||
#print [n.name.get_parent_until() for n in completions]
|
||||
print '#', len(completions)
|
||||
|
||||
@@ -147,4 +147,4 @@ c = b().c3()
|
||||
1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request;
|
||||
abc = [1,2+3]; abc[0].
|
||||
import pylab
|
||||
pylab.
|
||||
pylab.one
|
||||
|
||||
Reference in New Issue
Block a user