mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Remove the last usage of save/load_parser in jedi.
This commit is contained in:
@@ -20,9 +20,9 @@ from jedi._compatibility import find_module, unicode, ImplicitNSInfo
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.common import source_to_unicode, unite
|
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.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 sys_path
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate import compiled
|
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')) \
|
if path is not None and path.endswith(('.py', '.zip', '.egg')) \
|
||||||
and dotted_path not in settings.auto_import_modules:
|
and dotted_path not in settings.auto_import_modules:
|
||||||
|
|
||||||
cached = load_parser(evaluator.grammar, path)
|
module_node = parse(code=source, path=path, cache=True, diff_cache=True)
|
||||||
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()
|
|
||||||
|
|
||||||
from jedi.evaluate.representation import ModuleContext
|
from jedi.evaluate.representation import ModuleContext
|
||||||
return ModuleContext(evaluator, module_node)
|
return ModuleContext(evaluator, module_node)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from jedi.parser.python.parser import Parser, ParserWithRecovery, \
|
|||||||
from jedi.parser.python.diff import DiffParser
|
from jedi.parser.python.diff import DiffParser
|
||||||
from jedi.parser.tokenize import source_tokens
|
from jedi.parser.tokenize import source_tokens
|
||||||
from jedi.parser import utils
|
from jedi.parser import utils
|
||||||
from jedi.common import splitlines
|
from jedi.common import splitlines, source_to_unicode
|
||||||
|
|
||||||
|
|
||||||
_loaded_grammars = {}
|
_loaded_grammars = {}
|
||||||
@@ -84,8 +84,8 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
return p.get_root_node()
|
return p.get_root_node()
|
||||||
|
|
||||||
if code is None:
|
if code is None:
|
||||||
with open(path) as f:
|
with open(path, 'rb') as f:
|
||||||
code = f.read()
|
code = source_to_unicode(f.read())
|
||||||
|
|
||||||
added_newline = not code.endswith('\n')
|
added_newline = not code.endswith('\n')
|
||||||
if added_newline:
|
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)
|
p = parser(grammar, code, start_parsing=False, **kwargs)
|
||||||
new_node = p.parse(tokens=tokens)
|
new_node = p.parse(tokens=tokens)
|
||||||
if added_newline:
|
if added_newline:
|
||||||
p.source = code[:-1]
|
|
||||||
_remove_last_newline(new_node)
|
_remove_last_newline(new_node)
|
||||||
|
p.source = code[:-1]
|
||||||
|
|
||||||
if use_cache or diff_cache:
|
if use_cache or diff_cache:
|
||||||
utils.save_parser(grammar, path, p)
|
utils.save_parser(grammar, path, p)
|
||||||
|
|||||||
Reference in New Issue
Block a user