Remove the last usage of save/load_parser in jedi.

This commit is contained in:
Dave Halter
2017-03-26 01:48:45 +01:00
parent fb8ffde32e
commit aff0cbd68c
2 changed files with 7 additions and 17 deletions

View File

@@ -20,9 +20,9 @@ from jedi._compatibility import find_module, unicode, ImplicitNSInfo
from jedi import debug
from jedi import settings
from jedi.common import source_to_unicode, unite
from jedi.parser.python.diff import FastParser
from jedi.parser.python import parse
from jedi.parser.python import tree
from jedi.parser.utils import save_parser, load_parser, parser_cache
from jedi.parser.utils import parser_cache
from jedi.evaluate import sys_path
from jedi.evaluate import helpers
from jedi.evaluate import compiled
@@ -456,17 +456,7 @@ def _load_module(evaluator, path=None, source=None, sys_path=None, parent_module
if path is not None and path.endswith(('.py', '.zip', '.egg')) \
and dotted_path not in settings.auto_import_modules:
cached = load_parser(evaluator.grammar, path)
if cached is None:
if source is None:
with open(path, 'rb') as f:
source = f.read()
p = FastParser(evaluator.grammar, source_to_unicode(source), path)
save_parser(evaluator.grammar, path, p)
module_node = p.get_root_node()
else:
module_node = cached.get_root_node()
module_node = parse(code=source, path=path, cache=True, diff_cache=True)
from jedi.evaluate.representation import ModuleContext
return ModuleContext(evaluator, module_node)

View File

@@ -10,7 +10,7 @@ from jedi.parser.python.parser import Parser, ParserWithRecovery, \
from jedi.parser.python.diff import DiffParser
from jedi.parser.tokenize import source_tokens
from jedi.parser import utils
from jedi.common import splitlines
from jedi.common import splitlines, source_to_unicode
_loaded_grammars = {}
@@ -84,8 +84,8 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
return p.get_root_node()
if code is None:
with open(path) as f:
code = f.read()
with open(path, 'rb') as f:
code = source_to_unicode(f.read())
added_newline = not code.endswith('\n')
if added_newline:
@@ -119,8 +119,8 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
p = parser(grammar, code, start_parsing=False, **kwargs)
new_node = p.parse(tokens=tokens)
if added_newline:
p.source = code[:-1]
_remove_last_newline(new_node)
p.source = code[:-1]
if use_cache or diff_cache:
utils.save_parser(grammar, path, p)